1/*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
4 * Copyright (C) 2014 University of Washington. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 * THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28// DO NOT EDIT THIS FILE. It is automatically generated from CombinedDomains.json by the script: Source/JavaScriptCore/inspector/scripts/generate-inspector-protocol-bindings.py
29
30#include "config.h"
31#include "InspectorBackendDispatchers.h"
32
33#include "InspectorFrontendRouter.h"
34#include <wtf/NeverDestroyed.h>
35
36#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
37#include "InspectorAlternateBackendDispatchers.h"
38#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
39
40namespace Inspector {
41
42AnimationBackendDispatcherHandler::~AnimationBackendDispatcherHandler() { }
43ApplicationCacheBackendDispatcherHandler::~ApplicationCacheBackendDispatcherHandler() { }
44AuditBackendDispatcherHandler::~AuditBackendDispatcherHandler() { }
45BrowserBackendDispatcherHandler::~BrowserBackendDispatcherHandler() { }
46#if defined(ENABLE_RESOURCE_USAGE) && ENABLE_RESOURCE_USAGE
47CPUProfilerBackendDispatcherHandler::~CPUProfilerBackendDispatcherHandler() { }
48#endif // defined(ENABLE_RESOURCE_USAGE) && ENABLE_RESOURCE_USAGE
49CSSBackendDispatcherHandler::~CSSBackendDispatcherHandler() { }
50CanvasBackendDispatcherHandler::~CanvasBackendDispatcherHandler() { }
51ConsoleBackendDispatcherHandler::~ConsoleBackendDispatcherHandler() { }
52DOMBackendDispatcherHandler::~DOMBackendDispatcherHandler() { }
53DOMDebuggerBackendDispatcherHandler::~DOMDebuggerBackendDispatcherHandler() { }
54DOMStorageBackendDispatcherHandler::~DOMStorageBackendDispatcherHandler() { }
55DatabaseBackendDispatcherHandler::~DatabaseBackendDispatcherHandler() { }
56DebuggerBackendDispatcherHandler::~DebuggerBackendDispatcherHandler() { }
57HeapBackendDispatcherHandler::~HeapBackendDispatcherHandler() { }
58IndexedDBBackendDispatcherHandler::~IndexedDBBackendDispatcherHandler() { }
59InspectorBackendDispatcherHandler::~InspectorBackendDispatcherHandler() { }
60LayerTreeBackendDispatcherHandler::~LayerTreeBackendDispatcherHandler() { }
61#if defined(ENABLE_RESOURCE_USAGE) && ENABLE_RESOURCE_USAGE
62MemoryBackendDispatcherHandler::~MemoryBackendDispatcherHandler() { }
63#endif // defined(ENABLE_RESOURCE_USAGE) && ENABLE_RESOURCE_USAGE
64NetworkBackendDispatcherHandler::~NetworkBackendDispatcherHandler() { }
65PageBackendDispatcherHandler::~PageBackendDispatcherHandler() { }
66RuntimeBackendDispatcherHandler::~RuntimeBackendDispatcherHandler() { }
67ScriptProfilerBackendDispatcherHandler::~ScriptProfilerBackendDispatcherHandler() { }
68#if defined(ENABLE_SERVICE_WORKER) && ENABLE_SERVICE_WORKER
69ServiceWorkerBackendDispatcherHandler::~ServiceWorkerBackendDispatcherHandler() { }
70#endif // defined(ENABLE_SERVICE_WORKER) && ENABLE_SERVICE_WORKER
71TargetBackendDispatcherHandler::~TargetBackendDispatcherHandler() { }
72TimelineBackendDispatcherHandler::~TimelineBackendDispatcherHandler() { }
73WorkerBackendDispatcherHandler::~WorkerBackendDispatcherHandler() { }
74
75Ref<AnimationBackendDispatcher> AnimationBackendDispatcher::create(BackendDispatcher& backendDispatcher, AnimationBackendDispatcherHandler* agent)
76{
77 return adoptRef(*new AnimationBackendDispatcher(backendDispatcher, agent));
78}
79
80AnimationBackendDispatcher::AnimationBackendDispatcher(BackendDispatcher& backendDispatcher, AnimationBackendDispatcherHandler* agent)
81 : SupplementalBackendDispatcher(backendDispatcher)
82 , m_agent(agent)
83{
84 m_backendDispatcher->registerDispatcherForDomain("Animation"_s, this);
85}
86
87void AnimationBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
88{
89 Ref<AnimationBackendDispatcher> protect(*this);
90
91 auto protocol_parameters = protocol_message->getObject("params"_s);
92
93 using CallHandler = void (AnimationBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
94 using DispatchMap = HashMap<String, CallHandler>;
95 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
96 { "enable"_s, &AnimationBackendDispatcher::enable },
97 { "disable"_s, &AnimationBackendDispatcher::disable },
98 { "requestEffectTarget"_s, &AnimationBackendDispatcher::requestEffectTarget },
99 { "resolveAnimation"_s, &AnimationBackendDispatcher::resolveAnimation },
100 { "startTracking"_s, &AnimationBackendDispatcher::startTracking },
101 { "stopTracking"_s, &AnimationBackendDispatcher::stopTracking },
102 });
103
104 auto findResult = dispatchMap->find(protocol_method);
105 if (findResult == dispatchMap->end()) {
106 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Animation."_s, protocol_method, "' was not found"_s));
107 return;
108 }
109
110 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
111}
112
113void AnimationBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
114{
115#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
116 if (m_alternateDispatcher) {
117 m_alternateDispatcher->enable(protocol_requestId);
118 return;
119 }
120#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
121
122 auto result = m_agent->enable();
123 if (!result) {
124 ASSERT(!result.error().isEmpty());
125 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
126 return;
127 }
128
129 auto protocol_jsonMessage = JSON::Object::create();
130 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
131}
132
133void AnimationBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
134{
135#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
136 if (m_alternateDispatcher) {
137 m_alternateDispatcher->disable(protocol_requestId);
138 return;
139 }
140#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
141
142 auto result = m_agent->disable();
143 if (!result) {
144 ASSERT(!result.error().isEmpty());
145 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
146 return;
147 }
148
149 auto protocol_jsonMessage = JSON::Object::create();
150 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
151}
152
153void AnimationBackendDispatcher::requestEffectTarget(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
154{
155 auto in_animationId = m_backendDispatcher->getString(protocol_parameters.get(), "animationId"_s, true);
156 if (m_backendDispatcher->hasProtocolErrors()) {
157 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Animation.requestEffectTarget' can't be processed"_s);
158 return;
159 }
160
161#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
162 if (m_alternateDispatcher) {
163 m_alternateDispatcher->requestEffectTarget(protocol_requestId, in_animationId);
164 return;
165 }
166#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
167
168 auto result = m_agent->requestEffectTarget(in_animationId);
169 if (!result) {
170 ASSERT(!result.error().isEmpty());
171 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
172 return;
173 }
174
175 auto out_nodeId = WTFMove(result.value());
176
177 auto protocol_jsonMessage = JSON::Object::create();
178 protocol_jsonMessage->setInteger("nodeId"_s, out_nodeId);
179 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
180}
181
182void AnimationBackendDispatcher::resolveAnimation(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
183{
184 auto in_animationId = m_backendDispatcher->getString(protocol_parameters.get(), "animationId"_s, true);
185 auto in_opt_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, false);
186 if (m_backendDispatcher->hasProtocolErrors()) {
187 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Animation.resolveAnimation' can't be processed"_s);
188 return;
189 }
190
191#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
192 if (m_alternateDispatcher) {
193 m_alternateDispatcher->resolveAnimation(protocol_requestId, in_animationId, in_opt_objectGroup);
194 return;
195 }
196#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
197
198 auto result = m_agent->resolveAnimation(in_animationId, in_opt_objectGroup);
199 if (!result) {
200 ASSERT(!result.error().isEmpty());
201 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
202 return;
203 }
204
205 auto out_object = WTFMove(result.value());
206
207 auto protocol_jsonMessage = JSON::Object::create();
208 protocol_jsonMessage->setObject("object"_s, WTFMove(out_object));
209 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
210}
211
212void AnimationBackendDispatcher::startTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
213{
214#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
215 if (m_alternateDispatcher) {
216 m_alternateDispatcher->startTracking(protocol_requestId);
217 return;
218 }
219#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
220
221 auto result = m_agent->startTracking();
222 if (!result) {
223 ASSERT(!result.error().isEmpty());
224 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
225 return;
226 }
227
228 auto protocol_jsonMessage = JSON::Object::create();
229 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
230}
231
232void AnimationBackendDispatcher::stopTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
233{
234#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
235 if (m_alternateDispatcher) {
236 m_alternateDispatcher->stopTracking(protocol_requestId);
237 return;
238 }
239#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
240
241 auto result = m_agent->stopTracking();
242 if (!result) {
243 ASSERT(!result.error().isEmpty());
244 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
245 return;
246 }
247
248 auto protocol_jsonMessage = JSON::Object::create();
249 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
250}
251
252Ref<ApplicationCacheBackendDispatcher> ApplicationCacheBackendDispatcher::create(BackendDispatcher& backendDispatcher, ApplicationCacheBackendDispatcherHandler* agent)
253{
254 return adoptRef(*new ApplicationCacheBackendDispatcher(backendDispatcher, agent));
255}
256
257ApplicationCacheBackendDispatcher::ApplicationCacheBackendDispatcher(BackendDispatcher& backendDispatcher, ApplicationCacheBackendDispatcherHandler* agent)
258 : SupplementalBackendDispatcher(backendDispatcher)
259 , m_agent(agent)
260{
261 m_backendDispatcher->registerDispatcherForDomain("ApplicationCache"_s, this);
262}
263
264void ApplicationCacheBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
265{
266 Ref<ApplicationCacheBackendDispatcher> protect(*this);
267
268 auto protocol_parameters = protocol_message->getObject("params"_s);
269
270 if (protocol_method == "getFramesWithManifests"_s) {
271 getFramesWithManifests(protocol_requestId, WTFMove(protocol_parameters));
272 return;
273 }
274 if (protocol_method == "enable"_s) {
275 enable(protocol_requestId, WTFMove(protocol_parameters));
276 return;
277 }
278 if (protocol_method == "disable"_s) {
279 disable(protocol_requestId, WTFMove(protocol_parameters));
280 return;
281 }
282 if (protocol_method == "getManifestForFrame"_s) {
283 getManifestForFrame(protocol_requestId, WTFMove(protocol_parameters));
284 return;
285 }
286 if (protocol_method == "getApplicationCacheForFrame"_s) {
287 getApplicationCacheForFrame(protocol_requestId, WTFMove(protocol_parameters));
288 return;
289 }
290
291 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'ApplicationCache."_s, protocol_method, "' was not found"_s));
292}
293
294void ApplicationCacheBackendDispatcher::getFramesWithManifests(long protocol_requestId, RefPtr<JSON::Object>&&)
295{
296#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
297 if (m_alternateDispatcher) {
298 m_alternateDispatcher->getFramesWithManifests(protocol_requestId);
299 return;
300 }
301#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
302
303 auto result = m_agent->getFramesWithManifests();
304 if (!result) {
305 ASSERT(!result.error().isEmpty());
306 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
307 return;
308 }
309
310 auto out_frameIds = WTFMove(result.value());
311
312 auto protocol_jsonMessage = JSON::Object::create();
313 protocol_jsonMessage->setArray("frameIds"_s, WTFMove(out_frameIds));
314 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
315}
316
317void ApplicationCacheBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
318{
319#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
320 if (m_alternateDispatcher) {
321 m_alternateDispatcher->enable(protocol_requestId);
322 return;
323 }
324#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
325
326 auto result = m_agent->enable();
327 if (!result) {
328 ASSERT(!result.error().isEmpty());
329 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
330 return;
331 }
332
333 auto protocol_jsonMessage = JSON::Object::create();
334 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
335}
336
337void ApplicationCacheBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
338{
339#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
340 if (m_alternateDispatcher) {
341 m_alternateDispatcher->disable(protocol_requestId);
342 return;
343 }
344#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
345
346 auto result = m_agent->disable();
347 if (!result) {
348 ASSERT(!result.error().isEmpty());
349 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
350 return;
351 }
352
353 auto protocol_jsonMessage = JSON::Object::create();
354 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
355}
356
357void ApplicationCacheBackendDispatcher::getManifestForFrame(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
358{
359 auto in_frameId = m_backendDispatcher->getString(protocol_parameters.get(), "frameId"_s, true);
360 if (m_backendDispatcher->hasProtocolErrors()) {
361 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'ApplicationCache.getManifestForFrame' can't be processed"_s);
362 return;
363 }
364
365#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
366 if (m_alternateDispatcher) {
367 m_alternateDispatcher->getManifestForFrame(protocol_requestId, in_frameId);
368 return;
369 }
370#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
371
372 auto result = m_agent->getManifestForFrame(in_frameId);
373 if (!result) {
374 ASSERT(!result.error().isEmpty());
375 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
376 return;
377 }
378
379 auto out_manifestURL = WTFMove(result.value());
380
381 auto protocol_jsonMessage = JSON::Object::create();
382 protocol_jsonMessage->setString("manifestURL"_s, out_manifestURL);
383 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
384}
385
386void ApplicationCacheBackendDispatcher::getApplicationCacheForFrame(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
387{
388 auto in_frameId = m_backendDispatcher->getString(protocol_parameters.get(), "frameId"_s, true);
389 if (m_backendDispatcher->hasProtocolErrors()) {
390 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'ApplicationCache.getApplicationCacheForFrame' can't be processed"_s);
391 return;
392 }
393
394#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
395 if (m_alternateDispatcher) {
396 m_alternateDispatcher->getApplicationCacheForFrame(protocol_requestId, in_frameId);
397 return;
398 }
399#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
400
401 auto result = m_agent->getApplicationCacheForFrame(in_frameId);
402 if (!result) {
403 ASSERT(!result.error().isEmpty());
404 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
405 return;
406 }
407
408 auto out_applicationCache = WTFMove(result.value());
409
410 auto protocol_jsonMessage = JSON::Object::create();
411 protocol_jsonMessage->setObject("applicationCache"_s, WTFMove(out_applicationCache));
412 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
413}
414
415Ref<AuditBackendDispatcher> AuditBackendDispatcher::create(BackendDispatcher& backendDispatcher, AuditBackendDispatcherHandler* agent)
416{
417 return adoptRef(*new AuditBackendDispatcher(backendDispatcher, agent));
418}
419
420AuditBackendDispatcher::AuditBackendDispatcher(BackendDispatcher& backendDispatcher, AuditBackendDispatcherHandler* agent)
421 : SupplementalBackendDispatcher(backendDispatcher)
422 , m_agent(agent)
423{
424 m_backendDispatcher->registerDispatcherForDomain("Audit"_s, this);
425}
426
427void AuditBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
428{
429 Ref<AuditBackendDispatcher> protect(*this);
430
431 auto protocol_parameters = protocol_message->getObject("params"_s);
432
433 if (protocol_method == "setup"_s) {
434 setup(protocol_requestId, WTFMove(protocol_parameters));
435 return;
436 }
437 if (protocol_method == "run"_s) {
438 run(protocol_requestId, WTFMove(protocol_parameters));
439 return;
440 }
441 if (protocol_method == "teardown"_s) {
442 teardown(protocol_requestId, WTFMove(protocol_parameters));
443 return;
444 }
445
446 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Audit."_s, protocol_method, "' was not found"_s));
447}
448
449void AuditBackendDispatcher::setup(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
450{
451 auto in_opt_contextId = m_backendDispatcher->getInteger(protocol_parameters.get(), "contextId"_s, false);
452 if (m_backendDispatcher->hasProtocolErrors()) {
453 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Audit.setup' can't be processed"_s);
454 return;
455 }
456
457#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
458 if (m_alternateDispatcher) {
459 m_alternateDispatcher->setup(protocol_requestId, WTFMove(in_opt_contextId));
460 return;
461 }
462#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
463
464 auto result = m_agent->setup(WTFMove(in_opt_contextId));
465 if (!result) {
466 ASSERT(!result.error().isEmpty());
467 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
468 return;
469 }
470
471 auto protocol_jsonMessage = JSON::Object::create();
472 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
473}
474
475void AuditBackendDispatcher::run(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
476{
477 auto in_test = m_backendDispatcher->getString(protocol_parameters.get(), "test"_s, true);
478 auto in_opt_contextId = m_backendDispatcher->getInteger(protocol_parameters.get(), "contextId"_s, false);
479 if (m_backendDispatcher->hasProtocolErrors()) {
480 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Audit.run' can't be processed"_s);
481 return;
482 }
483
484#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
485 if (m_alternateDispatcher) {
486 m_alternateDispatcher->run(protocol_requestId, in_test, WTFMove(in_opt_contextId));
487 return;
488 }
489#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
490
491 auto result = m_agent->run(in_test, WTFMove(in_opt_contextId));
492 if (!result) {
493 ASSERT(!result.error().isEmpty());
494 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
495 return;
496 }
497
498 auto [out_result, out_opt_wasThrown] = WTFMove(result.value());
499
500 auto protocol_jsonMessage = JSON::Object::create();
501 protocol_jsonMessage->setObject("result"_s, WTFMove(out_result));
502 if (!!out_opt_wasThrown)
503 protocol_jsonMessage->setBoolean("wasThrown"_s, *out_opt_wasThrown);
504 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
505}
506
507void AuditBackendDispatcher::teardown(long protocol_requestId, RefPtr<JSON::Object>&&)
508{
509#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
510 if (m_alternateDispatcher) {
511 m_alternateDispatcher->teardown(protocol_requestId);
512 return;
513 }
514#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
515
516 auto result = m_agent->teardown();
517 if (!result) {
518 ASSERT(!result.error().isEmpty());
519 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
520 return;
521 }
522
523 auto protocol_jsonMessage = JSON::Object::create();
524 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
525}
526
527Ref<BrowserBackendDispatcher> BrowserBackendDispatcher::create(BackendDispatcher& backendDispatcher, BrowserBackendDispatcherHandler* agent)
528{
529 return adoptRef(*new BrowserBackendDispatcher(backendDispatcher, agent));
530}
531
532BrowserBackendDispatcher::BrowserBackendDispatcher(BackendDispatcher& backendDispatcher, BrowserBackendDispatcherHandler* agent)
533 : SupplementalBackendDispatcher(backendDispatcher)
534 , m_agent(agent)
535{
536 m_backendDispatcher->registerDispatcherForDomain("Browser"_s, this);
537}
538
539void BrowserBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
540{
541 Ref<BrowserBackendDispatcher> protect(*this);
542
543 auto protocol_parameters = protocol_message->getObject("params"_s);
544
545 if (protocol_method == "enable"_s) {
546 enable(protocol_requestId, WTFMove(protocol_parameters));
547 return;
548 }
549 if (protocol_method == "disable"_s) {
550 disable(protocol_requestId, WTFMove(protocol_parameters));
551 return;
552 }
553
554 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Browser."_s, protocol_method, "' was not found"_s));
555}
556
557void BrowserBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
558{
559#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
560 if (m_alternateDispatcher) {
561 m_alternateDispatcher->enable(protocol_requestId);
562 return;
563 }
564#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
565
566 auto result = m_agent->enable();
567 if (!result) {
568 ASSERT(!result.error().isEmpty());
569 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
570 return;
571 }
572
573 auto protocol_jsonMessage = JSON::Object::create();
574 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
575}
576
577void BrowserBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
578{
579#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
580 if (m_alternateDispatcher) {
581 m_alternateDispatcher->disable(protocol_requestId);
582 return;
583 }
584#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
585
586 auto result = m_agent->disable();
587 if (!result) {
588 ASSERT(!result.error().isEmpty());
589 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
590 return;
591 }
592
593 auto protocol_jsonMessage = JSON::Object::create();
594 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
595}
596
597#if defined(ENABLE_RESOURCE_USAGE) && ENABLE_RESOURCE_USAGE
598Ref<CPUProfilerBackendDispatcher> CPUProfilerBackendDispatcher::create(BackendDispatcher& backendDispatcher, CPUProfilerBackendDispatcherHandler* agent)
599{
600 return adoptRef(*new CPUProfilerBackendDispatcher(backendDispatcher, agent));
601}
602
603CPUProfilerBackendDispatcher::CPUProfilerBackendDispatcher(BackendDispatcher& backendDispatcher, CPUProfilerBackendDispatcherHandler* agent)
604 : SupplementalBackendDispatcher(backendDispatcher)
605 , m_agent(agent)
606{
607 m_backendDispatcher->registerDispatcherForDomain("CPUProfiler"_s, this);
608}
609
610void CPUProfilerBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
611{
612 Ref<CPUProfilerBackendDispatcher> protect(*this);
613
614 auto protocol_parameters = protocol_message->getObject("params"_s);
615
616 if (protocol_method == "startTracking"_s) {
617 startTracking(protocol_requestId, WTFMove(protocol_parameters));
618 return;
619 }
620 if (protocol_method == "stopTracking"_s) {
621 stopTracking(protocol_requestId, WTFMove(protocol_parameters));
622 return;
623 }
624
625 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'CPUProfiler."_s, protocol_method, "' was not found"_s));
626}
627
628void CPUProfilerBackendDispatcher::startTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
629{
630#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
631 if (m_alternateDispatcher) {
632 m_alternateDispatcher->startTracking(protocol_requestId);
633 return;
634 }
635#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
636
637 auto result = m_agent->startTracking();
638 if (!result) {
639 ASSERT(!result.error().isEmpty());
640 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
641 return;
642 }
643
644 auto protocol_jsonMessage = JSON::Object::create();
645 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
646}
647
648void CPUProfilerBackendDispatcher::stopTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
649{
650#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
651 if (m_alternateDispatcher) {
652 m_alternateDispatcher->stopTracking(protocol_requestId);
653 return;
654 }
655#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
656
657 auto result = m_agent->stopTracking();
658 if (!result) {
659 ASSERT(!result.error().isEmpty());
660 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
661 return;
662 }
663
664 auto protocol_jsonMessage = JSON::Object::create();
665 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
666}
667#endif // defined(ENABLE_RESOURCE_USAGE) && ENABLE_RESOURCE_USAGE
668
669Ref<CSSBackendDispatcher> CSSBackendDispatcher::create(BackendDispatcher& backendDispatcher, CSSBackendDispatcherHandler* agent)
670{
671 return adoptRef(*new CSSBackendDispatcher(backendDispatcher, agent));
672}
673
674CSSBackendDispatcher::CSSBackendDispatcher(BackendDispatcher& backendDispatcher, CSSBackendDispatcherHandler* agent)
675 : SupplementalBackendDispatcher(backendDispatcher)
676 , m_agent(agent)
677{
678 m_backendDispatcher->registerDispatcherForDomain("CSS"_s, this);
679}
680
681void CSSBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
682{
683 Ref<CSSBackendDispatcher> protect(*this);
684
685 auto protocol_parameters = protocol_message->getObject("params"_s);
686
687 using CallHandler = void (CSSBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
688 using DispatchMap = HashMap<String, CallHandler>;
689 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
690 { "enable"_s, &CSSBackendDispatcher::enable },
691 { "disable"_s, &CSSBackendDispatcher::disable },
692 { "getMatchedStylesForNode"_s, &CSSBackendDispatcher::getMatchedStylesForNode },
693 { "getInlineStylesForNode"_s, &CSSBackendDispatcher::getInlineStylesForNode },
694 { "getComputedStyleForNode"_s, &CSSBackendDispatcher::getComputedStyleForNode },
695 { "getFontDataForNode"_s, &CSSBackendDispatcher::getFontDataForNode },
696 { "getAllStyleSheets"_s, &CSSBackendDispatcher::getAllStyleSheets },
697 { "getStyleSheet"_s, &CSSBackendDispatcher::getStyleSheet },
698 { "getStyleSheetText"_s, &CSSBackendDispatcher::getStyleSheetText },
699 { "setStyleSheetText"_s, &CSSBackendDispatcher::setStyleSheetText },
700 { "setStyleText"_s, &CSSBackendDispatcher::setStyleText },
701 { "setRuleSelector"_s, &CSSBackendDispatcher::setRuleSelector },
702 { "createStyleSheet"_s, &CSSBackendDispatcher::createStyleSheet },
703 { "addRule"_s, &CSSBackendDispatcher::addRule },
704 { "getSupportedCSSProperties"_s, &CSSBackendDispatcher::getSupportedCSSProperties },
705 { "getSupportedSystemFontFamilyNames"_s, &CSSBackendDispatcher::getSupportedSystemFontFamilyNames },
706 { "forcePseudoState"_s, &CSSBackendDispatcher::forcePseudoState },
707 { "setLayoutContextTypeChangedMode"_s, &CSSBackendDispatcher::setLayoutContextTypeChangedMode },
708 });
709
710 auto findResult = dispatchMap->find(protocol_method);
711 if (findResult == dispatchMap->end()) {
712 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'CSS."_s, protocol_method, "' was not found"_s));
713 return;
714 }
715
716 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
717}
718
719void CSSBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
720{
721#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
722 if (m_alternateDispatcher) {
723 m_alternateDispatcher->enable(protocol_requestId);
724 return;
725 }
726#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
727
728 auto result = m_agent->enable();
729 if (!result) {
730 ASSERT(!result.error().isEmpty());
731 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
732 return;
733 }
734
735 auto protocol_jsonMessage = JSON::Object::create();
736 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
737}
738
739void CSSBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
740{
741#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
742 if (m_alternateDispatcher) {
743 m_alternateDispatcher->disable(protocol_requestId);
744 return;
745 }
746#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
747
748 auto result = m_agent->disable();
749 if (!result) {
750 ASSERT(!result.error().isEmpty());
751 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
752 return;
753 }
754
755 auto protocol_jsonMessage = JSON::Object::create();
756 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
757}
758
759void CSSBackendDispatcher::getMatchedStylesForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
760{
761 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
762 auto in_opt_includePseudo = m_backendDispatcher->getBoolean(protocol_parameters.get(), "includePseudo"_s, false);
763 auto in_opt_includeInherited = m_backendDispatcher->getBoolean(protocol_parameters.get(), "includeInherited"_s, false);
764 if (m_backendDispatcher->hasProtocolErrors()) {
765 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getMatchedStylesForNode' can't be processed"_s);
766 return;
767 }
768
769#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
770 if (m_alternateDispatcher) {
771 m_alternateDispatcher->getMatchedStylesForNode(protocol_requestId, *in_nodeId, WTFMove(in_opt_includePseudo), WTFMove(in_opt_includeInherited));
772 return;
773 }
774#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
775
776 auto result = m_agent->getMatchedStylesForNode(*in_nodeId, WTFMove(in_opt_includePseudo), WTFMove(in_opt_includeInherited));
777 if (!result) {
778 ASSERT(!result.error().isEmpty());
779 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
780 return;
781 }
782
783 auto [out_opt_matchedCSSRules, out_opt_pseudoElements, out_opt_inherited] = WTFMove(result.value());
784
785 auto protocol_jsonMessage = JSON::Object::create();
786 if (!!out_opt_matchedCSSRules)
787 protocol_jsonMessage->setArray("matchedCSSRules"_s, out_opt_matchedCSSRules.releaseNonNull());
788 if (!!out_opt_pseudoElements)
789 protocol_jsonMessage->setArray("pseudoElements"_s, out_opt_pseudoElements.releaseNonNull());
790 if (!!out_opt_inherited)
791 protocol_jsonMessage->setArray("inherited"_s, out_opt_inherited.releaseNonNull());
792 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
793}
794
795void CSSBackendDispatcher::getInlineStylesForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
796{
797 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
798 if (m_backendDispatcher->hasProtocolErrors()) {
799 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getInlineStylesForNode' can't be processed"_s);
800 return;
801 }
802
803#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
804 if (m_alternateDispatcher) {
805 m_alternateDispatcher->getInlineStylesForNode(protocol_requestId, *in_nodeId);
806 return;
807 }
808#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
809
810 auto result = m_agent->getInlineStylesForNode(*in_nodeId);
811 if (!result) {
812 ASSERT(!result.error().isEmpty());
813 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
814 return;
815 }
816
817 auto [out_opt_inlineStyle, out_opt_attributesStyle] = WTFMove(result.value());
818
819 auto protocol_jsonMessage = JSON::Object::create();
820 if (!!out_opt_inlineStyle)
821 protocol_jsonMessage->setObject("inlineStyle"_s, out_opt_inlineStyle.releaseNonNull());
822 if (!!out_opt_attributesStyle)
823 protocol_jsonMessage->setObject("attributesStyle"_s, out_opt_attributesStyle.releaseNonNull());
824 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
825}
826
827void CSSBackendDispatcher::getComputedStyleForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
828{
829 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
830 if (m_backendDispatcher->hasProtocolErrors()) {
831 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getComputedStyleForNode' can't be processed"_s);
832 return;
833 }
834
835#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
836 if (m_alternateDispatcher) {
837 m_alternateDispatcher->getComputedStyleForNode(protocol_requestId, *in_nodeId);
838 return;
839 }
840#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
841
842 auto result = m_agent->getComputedStyleForNode(*in_nodeId);
843 if (!result) {
844 ASSERT(!result.error().isEmpty());
845 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
846 return;
847 }
848
849 auto out_computedStyle = WTFMove(result.value());
850
851 auto protocol_jsonMessage = JSON::Object::create();
852 protocol_jsonMessage->setArray("computedStyle"_s, WTFMove(out_computedStyle));
853 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
854}
855
856void CSSBackendDispatcher::getFontDataForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
857{
858 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
859 if (m_backendDispatcher->hasProtocolErrors()) {
860 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getFontDataForNode' can't be processed"_s);
861 return;
862 }
863
864#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
865 if (m_alternateDispatcher) {
866 m_alternateDispatcher->getFontDataForNode(protocol_requestId, *in_nodeId);
867 return;
868 }
869#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
870
871 auto result = m_agent->getFontDataForNode(*in_nodeId);
872 if (!result) {
873 ASSERT(!result.error().isEmpty());
874 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
875 return;
876 }
877
878 auto out_primaryFont = WTFMove(result.value());
879
880 auto protocol_jsonMessage = JSON::Object::create();
881 protocol_jsonMessage->setObject("primaryFont"_s, WTFMove(out_primaryFont));
882 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
883}
884
885void CSSBackendDispatcher::getAllStyleSheets(long protocol_requestId, RefPtr<JSON::Object>&&)
886{
887#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
888 if (m_alternateDispatcher) {
889 m_alternateDispatcher->getAllStyleSheets(protocol_requestId);
890 return;
891 }
892#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
893
894 auto result = m_agent->getAllStyleSheets();
895 if (!result) {
896 ASSERT(!result.error().isEmpty());
897 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
898 return;
899 }
900
901 auto out_headers = WTFMove(result.value());
902
903 auto protocol_jsonMessage = JSON::Object::create();
904 protocol_jsonMessage->setArray("headers"_s, WTFMove(out_headers));
905 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
906}
907
908void CSSBackendDispatcher::getStyleSheet(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
909{
910 auto in_styleSheetId = m_backendDispatcher->getString(protocol_parameters.get(), "styleSheetId"_s, true);
911 if (m_backendDispatcher->hasProtocolErrors()) {
912 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getStyleSheet' can't be processed"_s);
913 return;
914 }
915
916#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
917 if (m_alternateDispatcher) {
918 m_alternateDispatcher->getStyleSheet(protocol_requestId, in_styleSheetId);
919 return;
920 }
921#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
922
923 auto result = m_agent->getStyleSheet(in_styleSheetId);
924 if (!result) {
925 ASSERT(!result.error().isEmpty());
926 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
927 return;
928 }
929
930 auto out_styleSheet = WTFMove(result.value());
931
932 auto protocol_jsonMessage = JSON::Object::create();
933 protocol_jsonMessage->setObject("styleSheet"_s, WTFMove(out_styleSheet));
934 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
935}
936
937void CSSBackendDispatcher::getStyleSheetText(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
938{
939 auto in_styleSheetId = m_backendDispatcher->getString(protocol_parameters.get(), "styleSheetId"_s, true);
940 if (m_backendDispatcher->hasProtocolErrors()) {
941 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.getStyleSheetText' can't be processed"_s);
942 return;
943 }
944
945#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
946 if (m_alternateDispatcher) {
947 m_alternateDispatcher->getStyleSheetText(protocol_requestId, in_styleSheetId);
948 return;
949 }
950#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
951
952 auto result = m_agent->getStyleSheetText(in_styleSheetId);
953 if (!result) {
954 ASSERT(!result.error().isEmpty());
955 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
956 return;
957 }
958
959 auto out_text = WTFMove(result.value());
960
961 auto protocol_jsonMessage = JSON::Object::create();
962 protocol_jsonMessage->setString("text"_s, out_text);
963 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
964}
965
966void CSSBackendDispatcher::setStyleSheetText(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
967{
968 auto in_styleSheetId = m_backendDispatcher->getString(protocol_parameters.get(), "styleSheetId"_s, true);
969 auto in_text = m_backendDispatcher->getString(protocol_parameters.get(), "text"_s, true);
970 if (m_backendDispatcher->hasProtocolErrors()) {
971 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.setStyleSheetText' can't be processed"_s);
972 return;
973 }
974
975#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
976 if (m_alternateDispatcher) {
977 m_alternateDispatcher->setStyleSheetText(protocol_requestId, in_styleSheetId, in_text);
978 return;
979 }
980#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
981
982 auto result = m_agent->setStyleSheetText(in_styleSheetId, in_text);
983 if (!result) {
984 ASSERT(!result.error().isEmpty());
985 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
986 return;
987 }
988
989 auto protocol_jsonMessage = JSON::Object::create();
990 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
991}
992
993void CSSBackendDispatcher::setStyleText(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
994{
995 auto in_styleId = m_backendDispatcher->getObject(protocol_parameters.get(), "styleId"_s, true);
996 auto in_text = m_backendDispatcher->getString(protocol_parameters.get(), "text"_s, true);
997 if (m_backendDispatcher->hasProtocolErrors()) {
998 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.setStyleText' can't be processed"_s);
999 return;
1000 }
1001
1002#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1003 if (m_alternateDispatcher) {
1004 m_alternateDispatcher->setStyleText(protocol_requestId, in_styleId.releaseNonNull(), in_text);
1005 return;
1006 }
1007#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1008
1009 auto result = m_agent->setStyleText(in_styleId.releaseNonNull(), in_text);
1010 if (!result) {
1011 ASSERT(!result.error().isEmpty());
1012 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1013 return;
1014 }
1015
1016 auto out_style = WTFMove(result.value());
1017
1018 auto protocol_jsonMessage = JSON::Object::create();
1019 protocol_jsonMessage->setObject("style"_s, WTFMove(out_style));
1020 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1021}
1022
1023void CSSBackendDispatcher::setRuleSelector(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1024{
1025 auto in_ruleId = m_backendDispatcher->getObject(protocol_parameters.get(), "ruleId"_s, true);
1026 auto in_selector = m_backendDispatcher->getString(protocol_parameters.get(), "selector"_s, true);
1027 if (m_backendDispatcher->hasProtocolErrors()) {
1028 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.setRuleSelector' can't be processed"_s);
1029 return;
1030 }
1031
1032#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1033 if (m_alternateDispatcher) {
1034 m_alternateDispatcher->setRuleSelector(protocol_requestId, in_ruleId.releaseNonNull(), in_selector);
1035 return;
1036 }
1037#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1038
1039 auto result = m_agent->setRuleSelector(in_ruleId.releaseNonNull(), in_selector);
1040 if (!result) {
1041 ASSERT(!result.error().isEmpty());
1042 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1043 return;
1044 }
1045
1046 auto out_rule = WTFMove(result.value());
1047
1048 auto protocol_jsonMessage = JSON::Object::create();
1049 protocol_jsonMessage->setObject("rule"_s, WTFMove(out_rule));
1050 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1051}
1052
1053void CSSBackendDispatcher::createStyleSheet(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1054{
1055 auto in_frameId = m_backendDispatcher->getString(protocol_parameters.get(), "frameId"_s, true);
1056 if (m_backendDispatcher->hasProtocolErrors()) {
1057 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.createStyleSheet' can't be processed"_s);
1058 return;
1059 }
1060
1061#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1062 if (m_alternateDispatcher) {
1063 m_alternateDispatcher->createStyleSheet(protocol_requestId, in_frameId);
1064 return;
1065 }
1066#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1067
1068 auto result = m_agent->createStyleSheet(in_frameId);
1069 if (!result) {
1070 ASSERT(!result.error().isEmpty());
1071 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1072 return;
1073 }
1074
1075 auto out_styleSheetId = WTFMove(result.value());
1076
1077 auto protocol_jsonMessage = JSON::Object::create();
1078 protocol_jsonMessage->setString("styleSheetId"_s, out_styleSheetId);
1079 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1080}
1081
1082void CSSBackendDispatcher::addRule(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1083{
1084 auto in_styleSheetId = m_backendDispatcher->getString(protocol_parameters.get(), "styleSheetId"_s, true);
1085 auto in_selector = m_backendDispatcher->getString(protocol_parameters.get(), "selector"_s, true);
1086 if (m_backendDispatcher->hasProtocolErrors()) {
1087 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.addRule' can't be processed"_s);
1088 return;
1089 }
1090
1091#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1092 if (m_alternateDispatcher) {
1093 m_alternateDispatcher->addRule(protocol_requestId, in_styleSheetId, in_selector);
1094 return;
1095 }
1096#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1097
1098 auto result = m_agent->addRule(in_styleSheetId, in_selector);
1099 if (!result) {
1100 ASSERT(!result.error().isEmpty());
1101 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1102 return;
1103 }
1104
1105 auto out_rule = WTFMove(result.value());
1106
1107 auto protocol_jsonMessage = JSON::Object::create();
1108 protocol_jsonMessage->setObject("rule"_s, WTFMove(out_rule));
1109 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1110}
1111
1112void CSSBackendDispatcher::getSupportedCSSProperties(long protocol_requestId, RefPtr<JSON::Object>&&)
1113{
1114#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1115 if (m_alternateDispatcher) {
1116 m_alternateDispatcher->getSupportedCSSProperties(protocol_requestId);
1117 return;
1118 }
1119#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1120
1121 auto result = m_agent->getSupportedCSSProperties();
1122 if (!result) {
1123 ASSERT(!result.error().isEmpty());
1124 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1125 return;
1126 }
1127
1128 auto out_cssProperties = WTFMove(result.value());
1129
1130 auto protocol_jsonMessage = JSON::Object::create();
1131 protocol_jsonMessage->setArray("cssProperties"_s, WTFMove(out_cssProperties));
1132 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1133}
1134
1135void CSSBackendDispatcher::getSupportedSystemFontFamilyNames(long protocol_requestId, RefPtr<JSON::Object>&&)
1136{
1137#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1138 if (m_alternateDispatcher) {
1139 m_alternateDispatcher->getSupportedSystemFontFamilyNames(protocol_requestId);
1140 return;
1141 }
1142#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1143
1144 auto result = m_agent->getSupportedSystemFontFamilyNames();
1145 if (!result) {
1146 ASSERT(!result.error().isEmpty());
1147 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1148 return;
1149 }
1150
1151 auto out_fontFamilyNames = WTFMove(result.value());
1152
1153 auto protocol_jsonMessage = JSON::Object::create();
1154 protocol_jsonMessage->setArray("fontFamilyNames"_s, WTFMove(out_fontFamilyNames));
1155 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1156}
1157
1158void CSSBackendDispatcher::forcePseudoState(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1159{
1160 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
1161 auto in_forcedPseudoClasses = m_backendDispatcher->getArray(protocol_parameters.get(), "forcedPseudoClasses"_s, true);
1162 if (m_backendDispatcher->hasProtocolErrors()) {
1163 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.forcePseudoState' can't be processed"_s);
1164 return;
1165 }
1166
1167#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1168 if (m_alternateDispatcher) {
1169 m_alternateDispatcher->forcePseudoState(protocol_requestId, *in_nodeId, in_forcedPseudoClasses.releaseNonNull());
1170 return;
1171 }
1172#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1173
1174 auto result = m_agent->forcePseudoState(*in_nodeId, in_forcedPseudoClasses.releaseNonNull());
1175 if (!result) {
1176 ASSERT(!result.error().isEmpty());
1177 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1178 return;
1179 }
1180
1181 auto protocol_jsonMessage = JSON::Object::create();
1182 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1183}
1184
1185void CSSBackendDispatcher::setLayoutContextTypeChangedMode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1186{
1187 auto in_mode_json = m_backendDispatcher->getString(protocol_parameters.get(), "mode"_s, true);
1188 if (m_backendDispatcher->hasProtocolErrors()) {
1189 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'CSS.setLayoutContextTypeChangedMode' can't be processed"_s);
1190 return;
1191 }
1192
1193#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1194 if (m_alternateDispatcher) {
1195 m_alternateDispatcher->setLayoutContextTypeChangedMode(protocol_requestId, in_mode_json);
1196 return;
1197 }
1198#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1199
1200 auto in_mode = Protocol::Helpers::parseEnumValueFromString<Protocol::CSS::LayoutContextTypeChangedMode>(in_mode_json);
1201 if (!in_mode) {
1202 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown mode: "_s, in_mode_json));
1203 return;
1204 }
1205
1206 auto result = m_agent->setLayoutContextTypeChangedMode(*in_mode);
1207 if (!result) {
1208 ASSERT(!result.error().isEmpty());
1209 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1210 return;
1211 }
1212
1213 auto protocol_jsonMessage = JSON::Object::create();
1214 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1215}
1216
1217Ref<CanvasBackendDispatcher> CanvasBackendDispatcher::create(BackendDispatcher& backendDispatcher, CanvasBackendDispatcherHandler* agent)
1218{
1219 return adoptRef(*new CanvasBackendDispatcher(backendDispatcher, agent));
1220}
1221
1222CanvasBackendDispatcher::CanvasBackendDispatcher(BackendDispatcher& backendDispatcher, CanvasBackendDispatcherHandler* agent)
1223 : SupplementalBackendDispatcher(backendDispatcher)
1224 , m_agent(agent)
1225{
1226 m_backendDispatcher->registerDispatcherForDomain("Canvas"_s, this);
1227}
1228
1229void CanvasBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
1230{
1231 Ref<CanvasBackendDispatcher> protect(*this);
1232
1233 auto protocol_parameters = protocol_message->getObject("params"_s);
1234
1235 using CallHandler = void (CanvasBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
1236 using DispatchMap = HashMap<String, CallHandler>;
1237 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
1238 { "enable"_s, &CanvasBackendDispatcher::enable },
1239 { "disable"_s, &CanvasBackendDispatcher::disable },
1240 { "requestNode"_s, &CanvasBackendDispatcher::requestNode },
1241 { "requestContent"_s, &CanvasBackendDispatcher::requestContent },
1242 { "requestClientNodes"_s, &CanvasBackendDispatcher::requestClientNodes },
1243 { "resolveContext"_s, &CanvasBackendDispatcher::resolveContext },
1244 { "setRecordingAutoCaptureFrameCount"_s, &CanvasBackendDispatcher::setRecordingAutoCaptureFrameCount },
1245 { "startRecording"_s, &CanvasBackendDispatcher::startRecording },
1246 { "stopRecording"_s, &CanvasBackendDispatcher::stopRecording },
1247#if (defined(ENABLE_WEBGL) && ENABLE_WEBGL) || (defined(ENABLE_WEBGPU) && ENABLE_WEBGPU)
1248 { "requestShaderSource"_s, &CanvasBackendDispatcher::requestShaderSource },
1249#endif // (defined(ENABLE_WEBGL) && ENABLE_WEBGL) || (defined(ENABLE_WEBGPU) && ENABLE_WEBGPU)
1250#if (defined(ENABLE_WEBGL) && ENABLE_WEBGL) || (defined(ENABLE_WEBGPU) && ENABLE_WEBGPU)
1251 { "updateShader"_s, &CanvasBackendDispatcher::updateShader },
1252#endif // (defined(ENABLE_WEBGL) && ENABLE_WEBGL) || (defined(ENABLE_WEBGPU) && ENABLE_WEBGPU)
1253#if defined(ENABLE_WEBGL) && ENABLE_WEBGL
1254 { "setShaderProgramDisabled"_s, &CanvasBackendDispatcher::setShaderProgramDisabled },
1255#endif // defined(ENABLE_WEBGL) && ENABLE_WEBGL
1256#if defined(ENABLE_WEBGL) && ENABLE_WEBGL
1257 { "setShaderProgramHighlighted"_s, &CanvasBackendDispatcher::setShaderProgramHighlighted },
1258#endif // defined(ENABLE_WEBGL) && ENABLE_WEBGL
1259 });
1260
1261 auto findResult = dispatchMap->find(protocol_method);
1262 if (findResult == dispatchMap->end()) {
1263 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Canvas."_s, protocol_method, "' was not found"_s));
1264 return;
1265 }
1266
1267 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
1268}
1269
1270void CanvasBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
1271{
1272#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1273 if (m_alternateDispatcher) {
1274 m_alternateDispatcher->enable(protocol_requestId);
1275 return;
1276 }
1277#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1278
1279 auto result = m_agent->enable();
1280 if (!result) {
1281 ASSERT(!result.error().isEmpty());
1282 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1283 return;
1284 }
1285
1286 auto protocol_jsonMessage = JSON::Object::create();
1287 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1288}
1289
1290void CanvasBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
1291{
1292#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1293 if (m_alternateDispatcher) {
1294 m_alternateDispatcher->disable(protocol_requestId);
1295 return;
1296 }
1297#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1298
1299 auto result = m_agent->disable();
1300 if (!result) {
1301 ASSERT(!result.error().isEmpty());
1302 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1303 return;
1304 }
1305
1306 auto protocol_jsonMessage = JSON::Object::create();
1307 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1308}
1309
1310void CanvasBackendDispatcher::requestNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1311{
1312 auto in_canvasId = m_backendDispatcher->getString(protocol_parameters.get(), "canvasId"_s, true);
1313 if (m_backendDispatcher->hasProtocolErrors()) {
1314 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.requestNode' can't be processed"_s);
1315 return;
1316 }
1317
1318#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1319 if (m_alternateDispatcher) {
1320 m_alternateDispatcher->requestNode(protocol_requestId, in_canvasId);
1321 return;
1322 }
1323#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1324
1325 auto result = m_agent->requestNode(in_canvasId);
1326 if (!result) {
1327 ASSERT(!result.error().isEmpty());
1328 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1329 return;
1330 }
1331
1332 auto out_nodeId = WTFMove(result.value());
1333
1334 auto protocol_jsonMessage = JSON::Object::create();
1335 protocol_jsonMessage->setInteger("nodeId"_s, out_nodeId);
1336 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1337}
1338
1339void CanvasBackendDispatcher::requestContent(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1340{
1341 auto in_canvasId = m_backendDispatcher->getString(protocol_parameters.get(), "canvasId"_s, true);
1342 if (m_backendDispatcher->hasProtocolErrors()) {
1343 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.requestContent' can't be processed"_s);
1344 return;
1345 }
1346
1347#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1348 if (m_alternateDispatcher) {
1349 m_alternateDispatcher->requestContent(protocol_requestId, in_canvasId);
1350 return;
1351 }
1352#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1353
1354 auto result = m_agent->requestContent(in_canvasId);
1355 if (!result) {
1356 ASSERT(!result.error().isEmpty());
1357 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1358 return;
1359 }
1360
1361 auto out_content = WTFMove(result.value());
1362
1363 auto protocol_jsonMessage = JSON::Object::create();
1364 protocol_jsonMessage->setString("content"_s, out_content);
1365 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1366}
1367
1368void CanvasBackendDispatcher::requestClientNodes(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1369{
1370 auto in_canvasId = m_backendDispatcher->getString(protocol_parameters.get(), "canvasId"_s, true);
1371 if (m_backendDispatcher->hasProtocolErrors()) {
1372 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.requestClientNodes' can't be processed"_s);
1373 return;
1374 }
1375
1376#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1377 if (m_alternateDispatcher) {
1378 m_alternateDispatcher->requestClientNodes(protocol_requestId, in_canvasId);
1379 return;
1380 }
1381#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1382
1383 auto result = m_agent->requestClientNodes(in_canvasId);
1384 if (!result) {
1385 ASSERT(!result.error().isEmpty());
1386 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1387 return;
1388 }
1389
1390 auto out_clientNodeIds = WTFMove(result.value());
1391
1392 auto protocol_jsonMessage = JSON::Object::create();
1393 protocol_jsonMessage->setArray("clientNodeIds"_s, WTFMove(out_clientNodeIds));
1394 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1395}
1396
1397void CanvasBackendDispatcher::resolveContext(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1398{
1399 auto in_canvasId = m_backendDispatcher->getString(protocol_parameters.get(), "canvasId"_s, true);
1400 auto in_opt_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, false);
1401 if (m_backendDispatcher->hasProtocolErrors()) {
1402 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.resolveContext' can't be processed"_s);
1403 return;
1404 }
1405
1406#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1407 if (m_alternateDispatcher) {
1408 m_alternateDispatcher->resolveContext(protocol_requestId, in_canvasId, in_opt_objectGroup);
1409 return;
1410 }
1411#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1412
1413 auto result = m_agent->resolveContext(in_canvasId, in_opt_objectGroup);
1414 if (!result) {
1415 ASSERT(!result.error().isEmpty());
1416 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1417 return;
1418 }
1419
1420 auto out_object = WTFMove(result.value());
1421
1422 auto protocol_jsonMessage = JSON::Object::create();
1423 protocol_jsonMessage->setObject("object"_s, WTFMove(out_object));
1424 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1425}
1426
1427void CanvasBackendDispatcher::setRecordingAutoCaptureFrameCount(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1428{
1429 auto in_count = m_backendDispatcher->getInteger(protocol_parameters.get(), "count"_s, true);
1430 if (m_backendDispatcher->hasProtocolErrors()) {
1431 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.setRecordingAutoCaptureFrameCount' can't be processed"_s);
1432 return;
1433 }
1434
1435#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1436 if (m_alternateDispatcher) {
1437 m_alternateDispatcher->setRecordingAutoCaptureFrameCount(protocol_requestId, *in_count);
1438 return;
1439 }
1440#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1441
1442 auto result = m_agent->setRecordingAutoCaptureFrameCount(*in_count);
1443 if (!result) {
1444 ASSERT(!result.error().isEmpty());
1445 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1446 return;
1447 }
1448
1449 auto protocol_jsonMessage = JSON::Object::create();
1450 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1451}
1452
1453void CanvasBackendDispatcher::startRecording(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1454{
1455 auto in_canvasId = m_backendDispatcher->getString(protocol_parameters.get(), "canvasId"_s, true);
1456 auto in_opt_frameCount = m_backendDispatcher->getInteger(protocol_parameters.get(), "frameCount"_s, false);
1457 auto in_opt_memoryLimit = m_backendDispatcher->getInteger(protocol_parameters.get(), "memoryLimit"_s, false);
1458 if (m_backendDispatcher->hasProtocolErrors()) {
1459 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.startRecording' can't be processed"_s);
1460 return;
1461 }
1462
1463#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1464 if (m_alternateDispatcher) {
1465 m_alternateDispatcher->startRecording(protocol_requestId, in_canvasId, WTFMove(in_opt_frameCount), WTFMove(in_opt_memoryLimit));
1466 return;
1467 }
1468#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1469
1470 auto result = m_agent->startRecording(in_canvasId, WTFMove(in_opt_frameCount), WTFMove(in_opt_memoryLimit));
1471 if (!result) {
1472 ASSERT(!result.error().isEmpty());
1473 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1474 return;
1475 }
1476
1477 auto protocol_jsonMessage = JSON::Object::create();
1478 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1479}
1480
1481void CanvasBackendDispatcher::stopRecording(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1482{
1483 auto in_canvasId = m_backendDispatcher->getString(protocol_parameters.get(), "canvasId"_s, true);
1484 if (m_backendDispatcher->hasProtocolErrors()) {
1485 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.stopRecording' can't be processed"_s);
1486 return;
1487 }
1488
1489#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1490 if (m_alternateDispatcher) {
1491 m_alternateDispatcher->stopRecording(protocol_requestId, in_canvasId);
1492 return;
1493 }
1494#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1495
1496 auto result = m_agent->stopRecording(in_canvasId);
1497 if (!result) {
1498 ASSERT(!result.error().isEmpty());
1499 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1500 return;
1501 }
1502
1503 auto protocol_jsonMessage = JSON::Object::create();
1504 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1505}
1506
1507#if (defined(ENABLE_WEBGL) && ENABLE_WEBGL) || (defined(ENABLE_WEBGPU) && ENABLE_WEBGPU)
1508void CanvasBackendDispatcher::requestShaderSource(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1509{
1510 auto in_programId = m_backendDispatcher->getString(protocol_parameters.get(), "programId"_s, true);
1511 auto in_shaderType_json = m_backendDispatcher->getString(protocol_parameters.get(), "shaderType"_s, true);
1512 if (m_backendDispatcher->hasProtocolErrors()) {
1513 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.requestShaderSource' can't be processed"_s);
1514 return;
1515 }
1516
1517#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1518 if (m_alternateDispatcher) {
1519 m_alternateDispatcher->requestShaderSource(protocol_requestId, in_programId, in_shaderType_json);
1520 return;
1521 }
1522#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1523
1524 auto in_shaderType = Protocol::Helpers::parseEnumValueFromString<Protocol::Canvas::ShaderType>(in_shaderType_json);
1525 if (!in_shaderType) {
1526 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown shaderType: "_s, in_shaderType_json));
1527 return;
1528 }
1529
1530 auto result = m_agent->requestShaderSource(in_programId, *in_shaderType);
1531 if (!result) {
1532 ASSERT(!result.error().isEmpty());
1533 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1534 return;
1535 }
1536
1537 auto out_source = WTFMove(result.value());
1538
1539 auto protocol_jsonMessage = JSON::Object::create();
1540 protocol_jsonMessage->setString("source"_s, out_source);
1541 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1542}
1543#endif // (defined(ENABLE_WEBGL) && ENABLE_WEBGL) || (defined(ENABLE_WEBGPU) && ENABLE_WEBGPU)
1544
1545#if (defined(ENABLE_WEBGL) && ENABLE_WEBGL) || (defined(ENABLE_WEBGPU) && ENABLE_WEBGPU)
1546void CanvasBackendDispatcher::updateShader(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1547{
1548 auto in_programId = m_backendDispatcher->getString(protocol_parameters.get(), "programId"_s, true);
1549 auto in_shaderType_json = m_backendDispatcher->getString(protocol_parameters.get(), "shaderType"_s, true);
1550 auto in_source = m_backendDispatcher->getString(protocol_parameters.get(), "source"_s, true);
1551 if (m_backendDispatcher->hasProtocolErrors()) {
1552 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.updateShader' can't be processed"_s);
1553 return;
1554 }
1555
1556#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1557 if (m_alternateDispatcher) {
1558 m_alternateDispatcher->updateShader(protocol_requestId, in_programId, in_shaderType_json, in_source);
1559 return;
1560 }
1561#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1562
1563 auto in_shaderType = Protocol::Helpers::parseEnumValueFromString<Protocol::Canvas::ShaderType>(in_shaderType_json);
1564 if (!in_shaderType) {
1565 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown shaderType: "_s, in_shaderType_json));
1566 return;
1567 }
1568
1569 auto result = m_agent->updateShader(in_programId, *in_shaderType, in_source);
1570 if (!result) {
1571 ASSERT(!result.error().isEmpty());
1572 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1573 return;
1574 }
1575
1576 auto protocol_jsonMessage = JSON::Object::create();
1577 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1578}
1579#endif // (defined(ENABLE_WEBGL) && ENABLE_WEBGL) || (defined(ENABLE_WEBGPU) && ENABLE_WEBGPU)
1580
1581#if defined(ENABLE_WEBGL) && ENABLE_WEBGL
1582void CanvasBackendDispatcher::setShaderProgramDisabled(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1583{
1584 auto in_programId = m_backendDispatcher->getString(protocol_parameters.get(), "programId"_s, true);
1585 auto in_disabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "disabled"_s, true);
1586 if (m_backendDispatcher->hasProtocolErrors()) {
1587 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.setShaderProgramDisabled' can't be processed"_s);
1588 return;
1589 }
1590
1591#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1592 if (m_alternateDispatcher) {
1593 m_alternateDispatcher->setShaderProgramDisabled(protocol_requestId, in_programId, *in_disabled);
1594 return;
1595 }
1596#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1597
1598 auto result = m_agent->setShaderProgramDisabled(in_programId, *in_disabled);
1599 if (!result) {
1600 ASSERT(!result.error().isEmpty());
1601 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1602 return;
1603 }
1604
1605 auto protocol_jsonMessage = JSON::Object::create();
1606 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1607}
1608#endif // defined(ENABLE_WEBGL) && ENABLE_WEBGL
1609
1610#if defined(ENABLE_WEBGL) && ENABLE_WEBGL
1611void CanvasBackendDispatcher::setShaderProgramHighlighted(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1612{
1613 auto in_programId = m_backendDispatcher->getString(protocol_parameters.get(), "programId"_s, true);
1614 auto in_highlighted = m_backendDispatcher->getBoolean(protocol_parameters.get(), "highlighted"_s, true);
1615 if (m_backendDispatcher->hasProtocolErrors()) {
1616 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Canvas.setShaderProgramHighlighted' can't be processed"_s);
1617 return;
1618 }
1619
1620#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1621 if (m_alternateDispatcher) {
1622 m_alternateDispatcher->setShaderProgramHighlighted(protocol_requestId, in_programId, *in_highlighted);
1623 return;
1624 }
1625#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1626
1627 auto result = m_agent->setShaderProgramHighlighted(in_programId, *in_highlighted);
1628 if (!result) {
1629 ASSERT(!result.error().isEmpty());
1630 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1631 return;
1632 }
1633
1634 auto protocol_jsonMessage = JSON::Object::create();
1635 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1636}
1637#endif // defined(ENABLE_WEBGL) && ENABLE_WEBGL
1638
1639Ref<ConsoleBackendDispatcher> ConsoleBackendDispatcher::create(BackendDispatcher& backendDispatcher, ConsoleBackendDispatcherHandler* agent)
1640{
1641 return adoptRef(*new ConsoleBackendDispatcher(backendDispatcher, agent));
1642}
1643
1644ConsoleBackendDispatcher::ConsoleBackendDispatcher(BackendDispatcher& backendDispatcher, ConsoleBackendDispatcherHandler* agent)
1645 : SupplementalBackendDispatcher(backendDispatcher)
1646 , m_agent(agent)
1647{
1648 m_backendDispatcher->registerDispatcherForDomain("Console"_s, this);
1649}
1650
1651void ConsoleBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
1652{
1653 Ref<ConsoleBackendDispatcher> protect(*this);
1654
1655 auto protocol_parameters = protocol_message->getObject("params"_s);
1656
1657 if (protocol_method == "enable"_s) {
1658 enable(protocol_requestId, WTFMove(protocol_parameters));
1659 return;
1660 }
1661 if (protocol_method == "disable"_s) {
1662 disable(protocol_requestId, WTFMove(protocol_parameters));
1663 return;
1664 }
1665 if (protocol_method == "clearMessages"_s) {
1666 clearMessages(protocol_requestId, WTFMove(protocol_parameters));
1667 return;
1668 }
1669 if (protocol_method == "getLoggingChannels"_s) {
1670 getLoggingChannels(protocol_requestId, WTFMove(protocol_parameters));
1671 return;
1672 }
1673 if (protocol_method == "setLoggingChannelLevel"_s) {
1674 setLoggingChannelLevel(protocol_requestId, WTFMove(protocol_parameters));
1675 return;
1676 }
1677
1678 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Console."_s, protocol_method, "' was not found"_s));
1679}
1680
1681void ConsoleBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
1682{
1683#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1684 if (m_alternateDispatcher) {
1685 m_alternateDispatcher->enable(protocol_requestId);
1686 return;
1687 }
1688#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1689
1690 auto result = m_agent->enable();
1691 if (!result) {
1692 ASSERT(!result.error().isEmpty());
1693 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1694 return;
1695 }
1696
1697 auto protocol_jsonMessage = JSON::Object::create();
1698 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1699}
1700
1701void ConsoleBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
1702{
1703#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1704 if (m_alternateDispatcher) {
1705 m_alternateDispatcher->disable(protocol_requestId);
1706 return;
1707 }
1708#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1709
1710 auto result = m_agent->disable();
1711 if (!result) {
1712 ASSERT(!result.error().isEmpty());
1713 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1714 return;
1715 }
1716
1717 auto protocol_jsonMessage = JSON::Object::create();
1718 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1719}
1720
1721void ConsoleBackendDispatcher::clearMessages(long protocol_requestId, RefPtr<JSON::Object>&&)
1722{
1723#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1724 if (m_alternateDispatcher) {
1725 m_alternateDispatcher->clearMessages(protocol_requestId);
1726 return;
1727 }
1728#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1729
1730 auto result = m_agent->clearMessages();
1731 if (!result) {
1732 ASSERT(!result.error().isEmpty());
1733 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1734 return;
1735 }
1736
1737 auto protocol_jsonMessage = JSON::Object::create();
1738 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1739}
1740
1741void ConsoleBackendDispatcher::getLoggingChannels(long protocol_requestId, RefPtr<JSON::Object>&&)
1742{
1743#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1744 if (m_alternateDispatcher) {
1745 m_alternateDispatcher->getLoggingChannels(protocol_requestId);
1746 return;
1747 }
1748#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1749
1750 auto result = m_agent->getLoggingChannels();
1751 if (!result) {
1752 ASSERT(!result.error().isEmpty());
1753 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1754 return;
1755 }
1756
1757 auto out_channels = WTFMove(result.value());
1758
1759 auto protocol_jsonMessage = JSON::Object::create();
1760 protocol_jsonMessage->setArray("channels"_s, WTFMove(out_channels));
1761 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1762}
1763
1764void ConsoleBackendDispatcher::setLoggingChannelLevel(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1765{
1766 auto in_source_json = m_backendDispatcher->getString(protocol_parameters.get(), "source"_s, true);
1767 auto in_level_json = m_backendDispatcher->getString(protocol_parameters.get(), "level"_s, true);
1768 if (m_backendDispatcher->hasProtocolErrors()) {
1769 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Console.setLoggingChannelLevel' can't be processed"_s);
1770 return;
1771 }
1772
1773#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1774 if (m_alternateDispatcher) {
1775 m_alternateDispatcher->setLoggingChannelLevel(protocol_requestId, in_source_json, in_level_json);
1776 return;
1777 }
1778#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1779
1780 auto in_source = Protocol::Helpers::parseEnumValueFromString<Protocol::Console::ChannelSource>(in_source_json);
1781 if (!in_source) {
1782 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown source: "_s, in_source_json));
1783 return;
1784 }
1785
1786 auto in_level = Protocol::Helpers::parseEnumValueFromString<Protocol::Console::ChannelLevel>(in_level_json);
1787 if (!in_level) {
1788 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown level: "_s, in_level_json));
1789 return;
1790 }
1791
1792 auto result = m_agent->setLoggingChannelLevel(*in_source, *in_level);
1793 if (!result) {
1794 ASSERT(!result.error().isEmpty());
1795 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1796 return;
1797 }
1798
1799 auto protocol_jsonMessage = JSON::Object::create();
1800 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1801}
1802
1803Ref<DOMBackendDispatcher> DOMBackendDispatcher::create(BackendDispatcher& backendDispatcher, DOMBackendDispatcherHandler* agent)
1804{
1805 return adoptRef(*new DOMBackendDispatcher(backendDispatcher, agent));
1806}
1807
1808DOMBackendDispatcher::DOMBackendDispatcher(BackendDispatcher& backendDispatcher, DOMBackendDispatcherHandler* agent)
1809 : SupplementalBackendDispatcher(backendDispatcher)
1810 , m_agent(agent)
1811{
1812 m_backendDispatcher->registerDispatcherForDomain("DOM"_s, this);
1813}
1814
1815void DOMBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
1816{
1817 Ref<DOMBackendDispatcher> protect(*this);
1818
1819 auto protocol_parameters = protocol_message->getObject("params"_s);
1820
1821 using CallHandler = void (DOMBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
1822 using DispatchMap = HashMap<String, CallHandler>;
1823 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
1824 { "getDocument"_s, &DOMBackendDispatcher::getDocument },
1825 { "requestChildNodes"_s, &DOMBackendDispatcher::requestChildNodes },
1826 { "querySelector"_s, &DOMBackendDispatcher::querySelector },
1827 { "querySelectorAll"_s, &DOMBackendDispatcher::querySelectorAll },
1828 { "setNodeName"_s, &DOMBackendDispatcher::setNodeName },
1829 { "setNodeValue"_s, &DOMBackendDispatcher::setNodeValue },
1830 { "removeNode"_s, &DOMBackendDispatcher::removeNode },
1831 { "setAttributeValue"_s, &DOMBackendDispatcher::setAttributeValue },
1832 { "setAttributesAsText"_s, &DOMBackendDispatcher::setAttributesAsText },
1833 { "removeAttribute"_s, &DOMBackendDispatcher::removeAttribute },
1834 { "getSupportedEventNames"_s, &DOMBackendDispatcher::getSupportedEventNames },
1835#if defined(ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS) && ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS
1836 { "getDataBindingsForNode"_s, &DOMBackendDispatcher::getDataBindingsForNode },
1837#endif // defined(ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS) && ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS
1838#if defined(ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS) && ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS
1839 { "getAssociatedDataForNode"_s, &DOMBackendDispatcher::getAssociatedDataForNode },
1840#endif // defined(ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS) && ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS
1841 { "getEventListenersForNode"_s, &DOMBackendDispatcher::getEventListenersForNode },
1842 { "setEventListenerDisabled"_s, &DOMBackendDispatcher::setEventListenerDisabled },
1843 { "setBreakpointForEventListener"_s, &DOMBackendDispatcher::setBreakpointForEventListener },
1844 { "removeBreakpointForEventListener"_s, &DOMBackendDispatcher::removeBreakpointForEventListener },
1845 { "getAccessibilityPropertiesForNode"_s, &DOMBackendDispatcher::getAccessibilityPropertiesForNode },
1846 { "getOuterHTML"_s, &DOMBackendDispatcher::getOuterHTML },
1847 { "setOuterHTML"_s, &DOMBackendDispatcher::setOuterHTML },
1848 { "insertAdjacentHTML"_s, &DOMBackendDispatcher::insertAdjacentHTML },
1849 { "performSearch"_s, &DOMBackendDispatcher::performSearch },
1850 { "getSearchResults"_s, &DOMBackendDispatcher::getSearchResults },
1851 { "discardSearchResults"_s, &DOMBackendDispatcher::discardSearchResults },
1852 { "requestNode"_s, &DOMBackendDispatcher::requestNode },
1853#if defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY
1854 { "setInspectModeEnabled"_s, &DOMBackendDispatcher::setInspectModeEnabled },
1855#endif // defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY
1856#if !(defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
1857 { "setInspectModeEnabled"_s, &DOMBackendDispatcher::setInspectModeEnabled },
1858#endif // !(defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
1859 { "highlightRect"_s, &DOMBackendDispatcher::highlightRect },
1860 { "highlightQuad"_s, &DOMBackendDispatcher::highlightQuad },
1861 { "highlightSelector"_s, &DOMBackendDispatcher::highlightSelector },
1862 { "highlightNode"_s, &DOMBackendDispatcher::highlightNode },
1863 { "highlightNodeList"_s, &DOMBackendDispatcher::highlightNodeList },
1864 { "hideHighlight"_s, &DOMBackendDispatcher::hideHighlight },
1865 { "highlightFrame"_s, &DOMBackendDispatcher::highlightFrame },
1866 { "showGridOverlay"_s, &DOMBackendDispatcher::showGridOverlay },
1867 { "hideGridOverlay"_s, &DOMBackendDispatcher::hideGridOverlay },
1868 { "pushNodeByPathToFrontend"_s, &DOMBackendDispatcher::pushNodeByPathToFrontend },
1869 { "resolveNode"_s, &DOMBackendDispatcher::resolveNode },
1870 { "getAttributes"_s, &DOMBackendDispatcher::getAttributes },
1871 { "moveTo"_s, &DOMBackendDispatcher::moveTo },
1872 { "undo"_s, &DOMBackendDispatcher::undo },
1873 { "redo"_s, &DOMBackendDispatcher::redo },
1874 { "markUndoableState"_s, &DOMBackendDispatcher::markUndoableState },
1875 { "focus"_s, &DOMBackendDispatcher::focus },
1876 { "setInspectedNode"_s, &DOMBackendDispatcher::setInspectedNode },
1877 { "setAllowEditingUserAgentShadowTrees"_s, &DOMBackendDispatcher::setAllowEditingUserAgentShadowTrees },
1878 });
1879
1880 auto findResult = dispatchMap->find(protocol_method);
1881 if (findResult == dispatchMap->end()) {
1882 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'DOM."_s, protocol_method, "' was not found"_s));
1883 return;
1884 }
1885
1886 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
1887}
1888
1889void DOMBackendDispatcher::getDocument(long protocol_requestId, RefPtr<JSON::Object>&&)
1890{
1891#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1892 if (m_alternateDispatcher) {
1893 m_alternateDispatcher->getDocument(protocol_requestId);
1894 return;
1895 }
1896#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1897
1898 auto result = m_agent->getDocument();
1899 if (!result) {
1900 ASSERT(!result.error().isEmpty());
1901 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1902 return;
1903 }
1904
1905 auto out_root = WTFMove(result.value());
1906
1907 auto protocol_jsonMessage = JSON::Object::create();
1908 protocol_jsonMessage->setObject("root"_s, WTFMove(out_root));
1909 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1910}
1911
1912void DOMBackendDispatcher::requestChildNodes(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1913{
1914 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
1915 auto in_opt_depth = m_backendDispatcher->getInteger(protocol_parameters.get(), "depth"_s, false);
1916 if (m_backendDispatcher->hasProtocolErrors()) {
1917 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.requestChildNodes' can't be processed"_s);
1918 return;
1919 }
1920
1921#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1922 if (m_alternateDispatcher) {
1923 m_alternateDispatcher->requestChildNodes(protocol_requestId, *in_nodeId, WTFMove(in_opt_depth));
1924 return;
1925 }
1926#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1927
1928 auto result = m_agent->requestChildNodes(*in_nodeId, WTFMove(in_opt_depth));
1929 if (!result) {
1930 ASSERT(!result.error().isEmpty());
1931 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1932 return;
1933 }
1934
1935 auto protocol_jsonMessage = JSON::Object::create();
1936 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1937}
1938
1939void DOMBackendDispatcher::querySelector(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1940{
1941 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
1942 auto in_selector = m_backendDispatcher->getString(protocol_parameters.get(), "selector"_s, true);
1943 if (m_backendDispatcher->hasProtocolErrors()) {
1944 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.querySelector' can't be processed"_s);
1945 return;
1946 }
1947
1948#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1949 if (m_alternateDispatcher) {
1950 m_alternateDispatcher->querySelector(protocol_requestId, *in_nodeId, in_selector);
1951 return;
1952 }
1953#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1954
1955 auto result = m_agent->querySelector(*in_nodeId, in_selector);
1956 if (!result) {
1957 ASSERT(!result.error().isEmpty());
1958 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1959 return;
1960 }
1961
1962 auto out_nodeId = WTFMove(result.value());
1963
1964 auto protocol_jsonMessage = JSON::Object::create();
1965 protocol_jsonMessage->setInteger("nodeId"_s, out_nodeId);
1966 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1967}
1968
1969void DOMBackendDispatcher::querySelectorAll(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
1970{
1971 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
1972 auto in_selector = m_backendDispatcher->getString(protocol_parameters.get(), "selector"_s, true);
1973 if (m_backendDispatcher->hasProtocolErrors()) {
1974 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.querySelectorAll' can't be processed"_s);
1975 return;
1976 }
1977
1978#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1979 if (m_alternateDispatcher) {
1980 m_alternateDispatcher->querySelectorAll(protocol_requestId, *in_nodeId, in_selector);
1981 return;
1982 }
1983#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
1984
1985 auto result = m_agent->querySelectorAll(*in_nodeId, in_selector);
1986 if (!result) {
1987 ASSERT(!result.error().isEmpty());
1988 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
1989 return;
1990 }
1991
1992 auto out_nodeIds = WTFMove(result.value());
1993
1994 auto protocol_jsonMessage = JSON::Object::create();
1995 protocol_jsonMessage->setArray("nodeIds"_s, WTFMove(out_nodeIds));
1996 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
1997}
1998
1999void DOMBackendDispatcher::setNodeName(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2000{
2001 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2002 auto in_name = m_backendDispatcher->getString(protocol_parameters.get(), "name"_s, true);
2003 if (m_backendDispatcher->hasProtocolErrors()) {
2004 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setNodeName' can't be processed"_s);
2005 return;
2006 }
2007
2008#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2009 if (m_alternateDispatcher) {
2010 m_alternateDispatcher->setNodeName(protocol_requestId, *in_nodeId, in_name);
2011 return;
2012 }
2013#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2014
2015 auto result = m_agent->setNodeName(*in_nodeId, in_name);
2016 if (!result) {
2017 ASSERT(!result.error().isEmpty());
2018 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2019 return;
2020 }
2021
2022 auto out_nodeId = WTFMove(result.value());
2023
2024 auto protocol_jsonMessage = JSON::Object::create();
2025 protocol_jsonMessage->setInteger("nodeId"_s, out_nodeId);
2026 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2027}
2028
2029void DOMBackendDispatcher::setNodeValue(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2030{
2031 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2032 auto in_value = m_backendDispatcher->getString(protocol_parameters.get(), "value"_s, true);
2033 if (m_backendDispatcher->hasProtocolErrors()) {
2034 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setNodeValue' can't be processed"_s);
2035 return;
2036 }
2037
2038#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2039 if (m_alternateDispatcher) {
2040 m_alternateDispatcher->setNodeValue(protocol_requestId, *in_nodeId, in_value);
2041 return;
2042 }
2043#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2044
2045 auto result = m_agent->setNodeValue(*in_nodeId, in_value);
2046 if (!result) {
2047 ASSERT(!result.error().isEmpty());
2048 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2049 return;
2050 }
2051
2052 auto protocol_jsonMessage = JSON::Object::create();
2053 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2054}
2055
2056void DOMBackendDispatcher::removeNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2057{
2058 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2059 if (m_backendDispatcher->hasProtocolErrors()) {
2060 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.removeNode' can't be processed"_s);
2061 return;
2062 }
2063
2064#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2065 if (m_alternateDispatcher) {
2066 m_alternateDispatcher->removeNode(protocol_requestId, *in_nodeId);
2067 return;
2068 }
2069#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2070
2071 auto result = m_agent->removeNode(*in_nodeId);
2072 if (!result) {
2073 ASSERT(!result.error().isEmpty());
2074 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2075 return;
2076 }
2077
2078 auto protocol_jsonMessage = JSON::Object::create();
2079 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2080}
2081
2082void DOMBackendDispatcher::setAttributeValue(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2083{
2084 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2085 auto in_name = m_backendDispatcher->getString(protocol_parameters.get(), "name"_s, true);
2086 auto in_value = m_backendDispatcher->getString(protocol_parameters.get(), "value"_s, true);
2087 if (m_backendDispatcher->hasProtocolErrors()) {
2088 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setAttributeValue' can't be processed"_s);
2089 return;
2090 }
2091
2092#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2093 if (m_alternateDispatcher) {
2094 m_alternateDispatcher->setAttributeValue(protocol_requestId, *in_nodeId, in_name, in_value);
2095 return;
2096 }
2097#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2098
2099 auto result = m_agent->setAttributeValue(*in_nodeId, in_name, in_value);
2100 if (!result) {
2101 ASSERT(!result.error().isEmpty());
2102 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2103 return;
2104 }
2105
2106 auto protocol_jsonMessage = JSON::Object::create();
2107 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2108}
2109
2110void DOMBackendDispatcher::setAttributesAsText(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2111{
2112 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2113 auto in_text = m_backendDispatcher->getString(protocol_parameters.get(), "text"_s, true);
2114 auto in_opt_name = m_backendDispatcher->getString(protocol_parameters.get(), "name"_s, false);
2115 if (m_backendDispatcher->hasProtocolErrors()) {
2116 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setAttributesAsText' can't be processed"_s);
2117 return;
2118 }
2119
2120#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2121 if (m_alternateDispatcher) {
2122 m_alternateDispatcher->setAttributesAsText(protocol_requestId, *in_nodeId, in_text, in_opt_name);
2123 return;
2124 }
2125#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2126
2127 auto result = m_agent->setAttributesAsText(*in_nodeId, in_text, in_opt_name);
2128 if (!result) {
2129 ASSERT(!result.error().isEmpty());
2130 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2131 return;
2132 }
2133
2134 auto protocol_jsonMessage = JSON::Object::create();
2135 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2136}
2137
2138void DOMBackendDispatcher::removeAttribute(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2139{
2140 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2141 auto in_name = m_backendDispatcher->getString(protocol_parameters.get(), "name"_s, true);
2142 if (m_backendDispatcher->hasProtocolErrors()) {
2143 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.removeAttribute' can't be processed"_s);
2144 return;
2145 }
2146
2147#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2148 if (m_alternateDispatcher) {
2149 m_alternateDispatcher->removeAttribute(protocol_requestId, *in_nodeId, in_name);
2150 return;
2151 }
2152#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2153
2154 auto result = m_agent->removeAttribute(*in_nodeId, in_name);
2155 if (!result) {
2156 ASSERT(!result.error().isEmpty());
2157 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2158 return;
2159 }
2160
2161 auto protocol_jsonMessage = JSON::Object::create();
2162 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2163}
2164
2165void DOMBackendDispatcher::getSupportedEventNames(long protocol_requestId, RefPtr<JSON::Object>&&)
2166{
2167#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2168 if (m_alternateDispatcher) {
2169 m_alternateDispatcher->getSupportedEventNames(protocol_requestId);
2170 return;
2171 }
2172#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2173
2174 auto result = m_agent->getSupportedEventNames();
2175 if (!result) {
2176 ASSERT(!result.error().isEmpty());
2177 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2178 return;
2179 }
2180
2181 auto out_eventNames = WTFMove(result.value());
2182
2183 auto protocol_jsonMessage = JSON::Object::create();
2184 protocol_jsonMessage->setArray("eventNames"_s, WTFMove(out_eventNames));
2185 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2186}
2187
2188#if defined(ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS) && ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS
2189void DOMBackendDispatcher::getDataBindingsForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2190{
2191 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2192 if (m_backendDispatcher->hasProtocolErrors()) {
2193 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getDataBindingsForNode' can't be processed"_s);
2194 return;
2195 }
2196
2197#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2198 if (m_alternateDispatcher) {
2199 m_alternateDispatcher->getDataBindingsForNode(protocol_requestId, *in_nodeId);
2200 return;
2201 }
2202#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2203
2204 auto result = m_agent->getDataBindingsForNode(*in_nodeId);
2205 if (!result) {
2206 ASSERT(!result.error().isEmpty());
2207 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2208 return;
2209 }
2210
2211 auto out_dataBindings = WTFMove(result.value());
2212
2213 auto protocol_jsonMessage = JSON::Object::create();
2214 protocol_jsonMessage->setArray("dataBindings"_s, WTFMove(out_dataBindings));
2215 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2216}
2217#endif // defined(ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS) && ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS
2218
2219#if defined(ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS) && ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS
2220void DOMBackendDispatcher::getAssociatedDataForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2221{
2222 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2223 if (m_backendDispatcher->hasProtocolErrors()) {
2224 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getAssociatedDataForNode' can't be processed"_s);
2225 return;
2226 }
2227
2228#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2229 if (m_alternateDispatcher) {
2230 m_alternateDispatcher->getAssociatedDataForNode(protocol_requestId, *in_nodeId);
2231 return;
2232 }
2233#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2234
2235 auto result = m_agent->getAssociatedDataForNode(*in_nodeId);
2236 if (!result) {
2237 ASSERT(!result.error().isEmpty());
2238 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2239 return;
2240 }
2241
2242 auto out_opt_associatedData = WTFMove(result.value());
2243
2244 auto protocol_jsonMessage = JSON::Object::create();
2245 if (!!out_opt_associatedData)
2246 protocol_jsonMessage->setString("associatedData"_s, out_opt_associatedData);
2247 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2248}
2249#endif // defined(ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS) && ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS
2250
2251void DOMBackendDispatcher::getEventListenersForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2252{
2253 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2254 if (m_backendDispatcher->hasProtocolErrors()) {
2255 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getEventListenersForNode' can't be processed"_s);
2256 return;
2257 }
2258
2259#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2260 if (m_alternateDispatcher) {
2261 m_alternateDispatcher->getEventListenersForNode(protocol_requestId, *in_nodeId);
2262 return;
2263 }
2264#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2265
2266 auto result = m_agent->getEventListenersForNode(*in_nodeId);
2267 if (!result) {
2268 ASSERT(!result.error().isEmpty());
2269 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2270 return;
2271 }
2272
2273 auto out_listeners = WTFMove(result.value());
2274
2275 auto protocol_jsonMessage = JSON::Object::create();
2276 protocol_jsonMessage->setArray("listeners"_s, WTFMove(out_listeners));
2277 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2278}
2279
2280void DOMBackendDispatcher::setEventListenerDisabled(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2281{
2282 auto in_eventListenerId = m_backendDispatcher->getInteger(protocol_parameters.get(), "eventListenerId"_s, true);
2283 auto in_disabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "disabled"_s, true);
2284 if (m_backendDispatcher->hasProtocolErrors()) {
2285 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setEventListenerDisabled' can't be processed"_s);
2286 return;
2287 }
2288
2289#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2290 if (m_alternateDispatcher) {
2291 m_alternateDispatcher->setEventListenerDisabled(protocol_requestId, *in_eventListenerId, *in_disabled);
2292 return;
2293 }
2294#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2295
2296 auto result = m_agent->setEventListenerDisabled(*in_eventListenerId, *in_disabled);
2297 if (!result) {
2298 ASSERT(!result.error().isEmpty());
2299 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2300 return;
2301 }
2302
2303 auto protocol_jsonMessage = JSON::Object::create();
2304 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2305}
2306
2307void DOMBackendDispatcher::setBreakpointForEventListener(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2308{
2309 auto in_eventListenerId = m_backendDispatcher->getInteger(protocol_parameters.get(), "eventListenerId"_s, true);
2310 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
2311 if (m_backendDispatcher->hasProtocolErrors()) {
2312 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setBreakpointForEventListener' can't be processed"_s);
2313 return;
2314 }
2315
2316#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2317 if (m_alternateDispatcher) {
2318 m_alternateDispatcher->setBreakpointForEventListener(protocol_requestId, *in_eventListenerId, WTFMove(in_opt_options));
2319 return;
2320 }
2321#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2322
2323 auto result = m_agent->setBreakpointForEventListener(*in_eventListenerId, WTFMove(in_opt_options));
2324 if (!result) {
2325 ASSERT(!result.error().isEmpty());
2326 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2327 return;
2328 }
2329
2330 auto protocol_jsonMessage = JSON::Object::create();
2331 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2332}
2333
2334void DOMBackendDispatcher::removeBreakpointForEventListener(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2335{
2336 auto in_eventListenerId = m_backendDispatcher->getInteger(protocol_parameters.get(), "eventListenerId"_s, true);
2337 if (m_backendDispatcher->hasProtocolErrors()) {
2338 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.removeBreakpointForEventListener' can't be processed"_s);
2339 return;
2340 }
2341
2342#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2343 if (m_alternateDispatcher) {
2344 m_alternateDispatcher->removeBreakpointForEventListener(protocol_requestId, *in_eventListenerId);
2345 return;
2346 }
2347#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2348
2349 auto result = m_agent->removeBreakpointForEventListener(*in_eventListenerId);
2350 if (!result) {
2351 ASSERT(!result.error().isEmpty());
2352 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2353 return;
2354 }
2355
2356 auto protocol_jsonMessage = JSON::Object::create();
2357 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2358}
2359
2360void DOMBackendDispatcher::getAccessibilityPropertiesForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2361{
2362 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2363 if (m_backendDispatcher->hasProtocolErrors()) {
2364 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getAccessibilityPropertiesForNode' can't be processed"_s);
2365 return;
2366 }
2367
2368#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2369 if (m_alternateDispatcher) {
2370 m_alternateDispatcher->getAccessibilityPropertiesForNode(protocol_requestId, *in_nodeId);
2371 return;
2372 }
2373#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2374
2375 auto result = m_agent->getAccessibilityPropertiesForNode(*in_nodeId);
2376 if (!result) {
2377 ASSERT(!result.error().isEmpty());
2378 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2379 return;
2380 }
2381
2382 auto out_properties = WTFMove(result.value());
2383
2384 auto protocol_jsonMessage = JSON::Object::create();
2385 protocol_jsonMessage->setObject("properties"_s, WTFMove(out_properties));
2386 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2387}
2388
2389void DOMBackendDispatcher::getOuterHTML(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2390{
2391 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2392 if (m_backendDispatcher->hasProtocolErrors()) {
2393 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getOuterHTML' can't be processed"_s);
2394 return;
2395 }
2396
2397#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2398 if (m_alternateDispatcher) {
2399 m_alternateDispatcher->getOuterHTML(protocol_requestId, *in_nodeId);
2400 return;
2401 }
2402#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2403
2404 auto result = m_agent->getOuterHTML(*in_nodeId);
2405 if (!result) {
2406 ASSERT(!result.error().isEmpty());
2407 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2408 return;
2409 }
2410
2411 auto out_outerHTML = WTFMove(result.value());
2412
2413 auto protocol_jsonMessage = JSON::Object::create();
2414 protocol_jsonMessage->setString("outerHTML"_s, out_outerHTML);
2415 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2416}
2417
2418void DOMBackendDispatcher::setOuterHTML(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2419{
2420 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2421 auto in_outerHTML = m_backendDispatcher->getString(protocol_parameters.get(), "outerHTML"_s, true);
2422 if (m_backendDispatcher->hasProtocolErrors()) {
2423 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setOuterHTML' can't be processed"_s);
2424 return;
2425 }
2426
2427#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2428 if (m_alternateDispatcher) {
2429 m_alternateDispatcher->setOuterHTML(protocol_requestId, *in_nodeId, in_outerHTML);
2430 return;
2431 }
2432#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2433
2434 auto result = m_agent->setOuterHTML(*in_nodeId, in_outerHTML);
2435 if (!result) {
2436 ASSERT(!result.error().isEmpty());
2437 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2438 return;
2439 }
2440
2441 auto protocol_jsonMessage = JSON::Object::create();
2442 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2443}
2444
2445void DOMBackendDispatcher::insertAdjacentHTML(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2446{
2447 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2448 auto in_position = m_backendDispatcher->getString(protocol_parameters.get(), "position"_s, true);
2449 auto in_html = m_backendDispatcher->getString(protocol_parameters.get(), "html"_s, true);
2450 if (m_backendDispatcher->hasProtocolErrors()) {
2451 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.insertAdjacentHTML' can't be processed"_s);
2452 return;
2453 }
2454
2455#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2456 if (m_alternateDispatcher) {
2457 m_alternateDispatcher->insertAdjacentHTML(protocol_requestId, *in_nodeId, in_position, in_html);
2458 return;
2459 }
2460#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2461
2462 auto result = m_agent->insertAdjacentHTML(*in_nodeId, in_position, in_html);
2463 if (!result) {
2464 ASSERT(!result.error().isEmpty());
2465 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2466 return;
2467 }
2468
2469 auto protocol_jsonMessage = JSON::Object::create();
2470 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2471}
2472
2473void DOMBackendDispatcher::performSearch(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2474{
2475 auto in_query = m_backendDispatcher->getString(protocol_parameters.get(), "query"_s, true);
2476 auto in_opt_nodeIds = m_backendDispatcher->getArray(protocol_parameters.get(), "nodeIds"_s, false);
2477 auto in_opt_caseSensitive = m_backendDispatcher->getBoolean(protocol_parameters.get(), "caseSensitive"_s, false);
2478 if (m_backendDispatcher->hasProtocolErrors()) {
2479 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.performSearch' can't be processed"_s);
2480 return;
2481 }
2482
2483#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2484 if (m_alternateDispatcher) {
2485 m_alternateDispatcher->performSearch(protocol_requestId, in_query, WTFMove(in_opt_nodeIds), WTFMove(in_opt_caseSensitive));
2486 return;
2487 }
2488#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2489
2490 auto result = m_agent->performSearch(in_query, WTFMove(in_opt_nodeIds), WTFMove(in_opt_caseSensitive));
2491 if (!result) {
2492 ASSERT(!result.error().isEmpty());
2493 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2494 return;
2495 }
2496
2497 auto [out_searchId, out_resultCount] = WTFMove(result.value());
2498
2499 auto protocol_jsonMessage = JSON::Object::create();
2500 protocol_jsonMessage->setString("searchId"_s, out_searchId);
2501 protocol_jsonMessage->setInteger("resultCount"_s, out_resultCount);
2502 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2503}
2504
2505void DOMBackendDispatcher::getSearchResults(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2506{
2507 auto in_searchId = m_backendDispatcher->getString(protocol_parameters.get(), "searchId"_s, true);
2508 auto in_fromIndex = m_backendDispatcher->getInteger(protocol_parameters.get(), "fromIndex"_s, true);
2509 auto in_toIndex = m_backendDispatcher->getInteger(protocol_parameters.get(), "toIndex"_s, true);
2510 if (m_backendDispatcher->hasProtocolErrors()) {
2511 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getSearchResults' can't be processed"_s);
2512 return;
2513 }
2514
2515#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2516 if (m_alternateDispatcher) {
2517 m_alternateDispatcher->getSearchResults(protocol_requestId, in_searchId, *in_fromIndex, *in_toIndex);
2518 return;
2519 }
2520#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2521
2522 auto result = m_agent->getSearchResults(in_searchId, *in_fromIndex, *in_toIndex);
2523 if (!result) {
2524 ASSERT(!result.error().isEmpty());
2525 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2526 return;
2527 }
2528
2529 auto out_nodeIds = WTFMove(result.value());
2530
2531 auto protocol_jsonMessage = JSON::Object::create();
2532 protocol_jsonMessage->setArray("nodeIds"_s, WTFMove(out_nodeIds));
2533 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2534}
2535
2536void DOMBackendDispatcher::discardSearchResults(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2537{
2538 auto in_searchId = m_backendDispatcher->getString(protocol_parameters.get(), "searchId"_s, true);
2539 if (m_backendDispatcher->hasProtocolErrors()) {
2540 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.discardSearchResults' can't be processed"_s);
2541 return;
2542 }
2543
2544#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2545 if (m_alternateDispatcher) {
2546 m_alternateDispatcher->discardSearchResults(protocol_requestId, in_searchId);
2547 return;
2548 }
2549#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2550
2551 auto result = m_agent->discardSearchResults(in_searchId);
2552 if (!result) {
2553 ASSERT(!result.error().isEmpty());
2554 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2555 return;
2556 }
2557
2558 auto protocol_jsonMessage = JSON::Object::create();
2559 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2560}
2561
2562void DOMBackendDispatcher::requestNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2563{
2564 auto in_objectId = m_backendDispatcher->getString(protocol_parameters.get(), "objectId"_s, true);
2565 if (m_backendDispatcher->hasProtocolErrors()) {
2566 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.requestNode' can't be processed"_s);
2567 return;
2568 }
2569
2570#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2571 if (m_alternateDispatcher) {
2572 m_alternateDispatcher->requestNode(protocol_requestId, in_objectId);
2573 return;
2574 }
2575#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2576
2577 auto result = m_agent->requestNode(in_objectId);
2578 if (!result) {
2579 ASSERT(!result.error().isEmpty());
2580 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2581 return;
2582 }
2583
2584 auto out_nodeId = WTFMove(result.value());
2585
2586 auto protocol_jsonMessage = JSON::Object::create();
2587 protocol_jsonMessage->setInteger("nodeId"_s, out_nodeId);
2588 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2589}
2590
2591#if defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY
2592void DOMBackendDispatcher::setInspectModeEnabled(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2593{
2594 auto in_enabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "enabled"_s, true);
2595 auto in_opt_highlightConfig = m_backendDispatcher->getObject(protocol_parameters.get(), "highlightConfig"_s, false);
2596 if (m_backendDispatcher->hasProtocolErrors()) {
2597 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setInspectModeEnabled' can't be processed"_s);
2598 return;
2599 }
2600
2601#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2602 if (m_alternateDispatcher) {
2603 m_alternateDispatcher->setInspectModeEnabled(protocol_requestId, *in_enabled, WTFMove(in_opt_highlightConfig));
2604 return;
2605 }
2606#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2607
2608 auto result = m_agent->setInspectModeEnabled(*in_enabled, WTFMove(in_opt_highlightConfig));
2609 if (!result) {
2610 ASSERT(!result.error().isEmpty());
2611 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2612 return;
2613 }
2614
2615 auto protocol_jsonMessage = JSON::Object::create();
2616 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2617}
2618#endif // defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY
2619
2620#if !(defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
2621void DOMBackendDispatcher::setInspectModeEnabled(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2622{
2623 auto in_enabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "enabled"_s, true);
2624 auto in_opt_highlightConfig = m_backendDispatcher->getObject(protocol_parameters.get(), "highlightConfig"_s, false);
2625 auto in_opt_showRulers = m_backendDispatcher->getBoolean(protocol_parameters.get(), "showRulers"_s, false);
2626 if (m_backendDispatcher->hasProtocolErrors()) {
2627 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setInspectModeEnabled' can't be processed"_s);
2628 return;
2629 }
2630
2631#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2632 if (m_alternateDispatcher) {
2633 m_alternateDispatcher->setInspectModeEnabled(protocol_requestId, *in_enabled, WTFMove(in_opt_highlightConfig), WTFMove(in_opt_showRulers));
2634 return;
2635 }
2636#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2637
2638 auto result = m_agent->setInspectModeEnabled(*in_enabled, WTFMove(in_opt_highlightConfig), WTFMove(in_opt_showRulers));
2639 if (!result) {
2640 ASSERT(!result.error().isEmpty());
2641 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2642 return;
2643 }
2644
2645 auto protocol_jsonMessage = JSON::Object::create();
2646 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2647}
2648#endif // !(defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
2649
2650void DOMBackendDispatcher::highlightRect(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2651{
2652 auto in_x = m_backendDispatcher->getInteger(protocol_parameters.get(), "x"_s, true);
2653 auto in_y = m_backendDispatcher->getInteger(protocol_parameters.get(), "y"_s, true);
2654 auto in_width = m_backendDispatcher->getInteger(protocol_parameters.get(), "width"_s, true);
2655 auto in_height = m_backendDispatcher->getInteger(protocol_parameters.get(), "height"_s, true);
2656 auto in_opt_color = m_backendDispatcher->getObject(protocol_parameters.get(), "color"_s, false);
2657 auto in_opt_outlineColor = m_backendDispatcher->getObject(protocol_parameters.get(), "outlineColor"_s, false);
2658 auto in_opt_usePageCoordinates = m_backendDispatcher->getBoolean(protocol_parameters.get(), "usePageCoordinates"_s, false);
2659 if (m_backendDispatcher->hasProtocolErrors()) {
2660 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightRect' can't be processed"_s);
2661 return;
2662 }
2663
2664#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2665 if (m_alternateDispatcher) {
2666 m_alternateDispatcher->highlightRect(protocol_requestId, *in_x, *in_y, *in_width, *in_height, WTFMove(in_opt_color), WTFMove(in_opt_outlineColor), WTFMove(in_opt_usePageCoordinates));
2667 return;
2668 }
2669#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2670
2671 auto result = m_agent->highlightRect(*in_x, *in_y, *in_width, *in_height, WTFMove(in_opt_color), WTFMove(in_opt_outlineColor), WTFMove(in_opt_usePageCoordinates));
2672 if (!result) {
2673 ASSERT(!result.error().isEmpty());
2674 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2675 return;
2676 }
2677
2678 auto protocol_jsonMessage = JSON::Object::create();
2679 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2680}
2681
2682void DOMBackendDispatcher::highlightQuad(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2683{
2684 auto in_quad = m_backendDispatcher->getArray(protocol_parameters.get(), "quad"_s, true);
2685 auto in_opt_color = m_backendDispatcher->getObject(protocol_parameters.get(), "color"_s, false);
2686 auto in_opt_outlineColor = m_backendDispatcher->getObject(protocol_parameters.get(), "outlineColor"_s, false);
2687 auto in_opt_usePageCoordinates = m_backendDispatcher->getBoolean(protocol_parameters.get(), "usePageCoordinates"_s, false);
2688 if (m_backendDispatcher->hasProtocolErrors()) {
2689 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightQuad' can't be processed"_s);
2690 return;
2691 }
2692
2693#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2694 if (m_alternateDispatcher) {
2695 m_alternateDispatcher->highlightQuad(protocol_requestId, in_quad.releaseNonNull(), WTFMove(in_opt_color), WTFMove(in_opt_outlineColor), WTFMove(in_opt_usePageCoordinates));
2696 return;
2697 }
2698#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2699
2700 auto result = m_agent->highlightQuad(in_quad.releaseNonNull(), WTFMove(in_opt_color), WTFMove(in_opt_outlineColor), WTFMove(in_opt_usePageCoordinates));
2701 if (!result) {
2702 ASSERT(!result.error().isEmpty());
2703 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2704 return;
2705 }
2706
2707 auto protocol_jsonMessage = JSON::Object::create();
2708 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2709}
2710
2711void DOMBackendDispatcher::highlightSelector(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2712{
2713 auto in_highlightConfig = m_backendDispatcher->getObject(protocol_parameters.get(), "highlightConfig"_s, true);
2714 auto in_selectorString = m_backendDispatcher->getString(protocol_parameters.get(), "selectorString"_s, true);
2715 auto in_opt_frameId = m_backendDispatcher->getString(protocol_parameters.get(), "frameId"_s, false);
2716 if (m_backendDispatcher->hasProtocolErrors()) {
2717 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightSelector' can't be processed"_s);
2718 return;
2719 }
2720
2721#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2722 if (m_alternateDispatcher) {
2723 m_alternateDispatcher->highlightSelector(protocol_requestId, in_highlightConfig.releaseNonNull(), in_selectorString, in_opt_frameId);
2724 return;
2725 }
2726#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2727
2728 auto result = m_agent->highlightSelector(in_highlightConfig.releaseNonNull(), in_selectorString, in_opt_frameId);
2729 if (!result) {
2730 ASSERT(!result.error().isEmpty());
2731 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2732 return;
2733 }
2734
2735 auto protocol_jsonMessage = JSON::Object::create();
2736 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2737}
2738
2739void DOMBackendDispatcher::highlightNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2740{
2741 auto in_highlightConfig = m_backendDispatcher->getObject(protocol_parameters.get(), "highlightConfig"_s, true);
2742 auto in_opt_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, false);
2743 auto in_opt_objectId = m_backendDispatcher->getString(protocol_parameters.get(), "objectId"_s, false);
2744 if (m_backendDispatcher->hasProtocolErrors()) {
2745 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightNode' can't be processed"_s);
2746 return;
2747 }
2748
2749#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2750 if (m_alternateDispatcher) {
2751 m_alternateDispatcher->highlightNode(protocol_requestId, in_highlightConfig.releaseNonNull(), WTFMove(in_opt_nodeId), in_opt_objectId);
2752 return;
2753 }
2754#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2755
2756 auto result = m_agent->highlightNode(in_highlightConfig.releaseNonNull(), WTFMove(in_opt_nodeId), in_opt_objectId);
2757 if (!result) {
2758 ASSERT(!result.error().isEmpty());
2759 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2760 return;
2761 }
2762
2763 auto protocol_jsonMessage = JSON::Object::create();
2764 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2765}
2766
2767void DOMBackendDispatcher::highlightNodeList(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2768{
2769 auto in_nodeIds = m_backendDispatcher->getArray(protocol_parameters.get(), "nodeIds"_s, true);
2770 auto in_highlightConfig = m_backendDispatcher->getObject(protocol_parameters.get(), "highlightConfig"_s, true);
2771 if (m_backendDispatcher->hasProtocolErrors()) {
2772 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightNodeList' can't be processed"_s);
2773 return;
2774 }
2775
2776#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2777 if (m_alternateDispatcher) {
2778 m_alternateDispatcher->highlightNodeList(protocol_requestId, in_nodeIds.releaseNonNull(), in_highlightConfig.releaseNonNull());
2779 return;
2780 }
2781#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2782
2783 auto result = m_agent->highlightNodeList(in_nodeIds.releaseNonNull(), in_highlightConfig.releaseNonNull());
2784 if (!result) {
2785 ASSERT(!result.error().isEmpty());
2786 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2787 return;
2788 }
2789
2790 auto protocol_jsonMessage = JSON::Object::create();
2791 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2792}
2793
2794void DOMBackendDispatcher::hideHighlight(long protocol_requestId, RefPtr<JSON::Object>&&)
2795{
2796#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2797 if (m_alternateDispatcher) {
2798 m_alternateDispatcher->hideHighlight(protocol_requestId);
2799 return;
2800 }
2801#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2802
2803 auto result = m_agent->hideHighlight();
2804 if (!result) {
2805 ASSERT(!result.error().isEmpty());
2806 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2807 return;
2808 }
2809
2810 auto protocol_jsonMessage = JSON::Object::create();
2811 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2812}
2813
2814void DOMBackendDispatcher::highlightFrame(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2815{
2816 auto in_frameId = m_backendDispatcher->getString(protocol_parameters.get(), "frameId"_s, true);
2817 auto in_opt_contentColor = m_backendDispatcher->getObject(protocol_parameters.get(), "contentColor"_s, false);
2818 auto in_opt_contentOutlineColor = m_backendDispatcher->getObject(protocol_parameters.get(), "contentOutlineColor"_s, false);
2819 if (m_backendDispatcher->hasProtocolErrors()) {
2820 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.highlightFrame' can't be processed"_s);
2821 return;
2822 }
2823
2824#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2825 if (m_alternateDispatcher) {
2826 m_alternateDispatcher->highlightFrame(protocol_requestId, in_frameId, WTFMove(in_opt_contentColor), WTFMove(in_opt_contentOutlineColor));
2827 return;
2828 }
2829#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2830
2831 auto result = m_agent->highlightFrame(in_frameId, WTFMove(in_opt_contentColor), WTFMove(in_opt_contentOutlineColor));
2832 if (!result) {
2833 ASSERT(!result.error().isEmpty());
2834 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2835 return;
2836 }
2837
2838 auto protocol_jsonMessage = JSON::Object::create();
2839 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2840}
2841
2842void DOMBackendDispatcher::showGridOverlay(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2843{
2844 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2845 auto in_gridColor = m_backendDispatcher->getObject(protocol_parameters.get(), "gridColor"_s, true);
2846 auto in_opt_showLineNames = m_backendDispatcher->getBoolean(protocol_parameters.get(), "showLineNames"_s, false);
2847 auto in_opt_showLineNumbers = m_backendDispatcher->getBoolean(protocol_parameters.get(), "showLineNumbers"_s, false);
2848 auto in_opt_showExtendedGridLines = m_backendDispatcher->getBoolean(protocol_parameters.get(), "showExtendedGridLines"_s, false);
2849 auto in_opt_showTrackSizes = m_backendDispatcher->getBoolean(protocol_parameters.get(), "showTrackSizes"_s, false);
2850 auto in_opt_showAreaNames = m_backendDispatcher->getBoolean(protocol_parameters.get(), "showAreaNames"_s, false);
2851 if (m_backendDispatcher->hasProtocolErrors()) {
2852 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.showGridOverlay' can't be processed"_s);
2853 return;
2854 }
2855
2856#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2857 if (m_alternateDispatcher) {
2858 m_alternateDispatcher->showGridOverlay(protocol_requestId, *in_nodeId, in_gridColor.releaseNonNull(), WTFMove(in_opt_showLineNames), WTFMove(in_opt_showLineNumbers), WTFMove(in_opt_showExtendedGridLines), WTFMove(in_opt_showTrackSizes), WTFMove(in_opt_showAreaNames));
2859 return;
2860 }
2861#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2862
2863 auto result = m_agent->showGridOverlay(*in_nodeId, in_gridColor.releaseNonNull(), WTFMove(in_opt_showLineNames), WTFMove(in_opt_showLineNumbers), WTFMove(in_opt_showExtendedGridLines), WTFMove(in_opt_showTrackSizes), WTFMove(in_opt_showAreaNames));
2864 if (!result) {
2865 ASSERT(!result.error().isEmpty());
2866 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2867 return;
2868 }
2869
2870 auto protocol_jsonMessage = JSON::Object::create();
2871 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2872}
2873
2874void DOMBackendDispatcher::hideGridOverlay(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2875{
2876 auto in_opt_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, false);
2877 if (m_backendDispatcher->hasProtocolErrors()) {
2878 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.hideGridOverlay' can't be processed"_s);
2879 return;
2880 }
2881
2882#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2883 if (m_alternateDispatcher) {
2884 m_alternateDispatcher->hideGridOverlay(protocol_requestId, WTFMove(in_opt_nodeId));
2885 return;
2886 }
2887#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2888
2889 auto result = m_agent->hideGridOverlay(WTFMove(in_opt_nodeId));
2890 if (!result) {
2891 ASSERT(!result.error().isEmpty());
2892 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2893 return;
2894 }
2895
2896 auto protocol_jsonMessage = JSON::Object::create();
2897 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2898}
2899
2900void DOMBackendDispatcher::pushNodeByPathToFrontend(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2901{
2902 auto in_path = m_backendDispatcher->getString(protocol_parameters.get(), "path"_s, true);
2903 if (m_backendDispatcher->hasProtocolErrors()) {
2904 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.pushNodeByPathToFrontend' can't be processed"_s);
2905 return;
2906 }
2907
2908#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2909 if (m_alternateDispatcher) {
2910 m_alternateDispatcher->pushNodeByPathToFrontend(protocol_requestId, in_path);
2911 return;
2912 }
2913#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2914
2915 auto result = m_agent->pushNodeByPathToFrontend(in_path);
2916 if (!result) {
2917 ASSERT(!result.error().isEmpty());
2918 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2919 return;
2920 }
2921
2922 auto out_nodeId = WTFMove(result.value());
2923
2924 auto protocol_jsonMessage = JSON::Object::create();
2925 protocol_jsonMessage->setInteger("nodeId"_s, out_nodeId);
2926 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2927}
2928
2929void DOMBackendDispatcher::resolveNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2930{
2931 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2932 auto in_opt_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, false);
2933 if (m_backendDispatcher->hasProtocolErrors()) {
2934 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.resolveNode' can't be processed"_s);
2935 return;
2936 }
2937
2938#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2939 if (m_alternateDispatcher) {
2940 m_alternateDispatcher->resolveNode(protocol_requestId, *in_nodeId, in_opt_objectGroup);
2941 return;
2942 }
2943#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2944
2945 auto result = m_agent->resolveNode(*in_nodeId, in_opt_objectGroup);
2946 if (!result) {
2947 ASSERT(!result.error().isEmpty());
2948 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2949 return;
2950 }
2951
2952 auto out_object = WTFMove(result.value());
2953
2954 auto protocol_jsonMessage = JSON::Object::create();
2955 protocol_jsonMessage->setObject("object"_s, WTFMove(out_object));
2956 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2957}
2958
2959void DOMBackendDispatcher::getAttributes(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2960{
2961 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2962 if (m_backendDispatcher->hasProtocolErrors()) {
2963 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.getAttributes' can't be processed"_s);
2964 return;
2965 }
2966
2967#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2968 if (m_alternateDispatcher) {
2969 m_alternateDispatcher->getAttributes(protocol_requestId, *in_nodeId);
2970 return;
2971 }
2972#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2973
2974 auto result = m_agent->getAttributes(*in_nodeId);
2975 if (!result) {
2976 ASSERT(!result.error().isEmpty());
2977 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
2978 return;
2979 }
2980
2981 auto out_attributes = WTFMove(result.value());
2982
2983 auto protocol_jsonMessage = JSON::Object::create();
2984 protocol_jsonMessage->setArray("attributes"_s, WTFMove(out_attributes));
2985 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
2986}
2987
2988void DOMBackendDispatcher::moveTo(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
2989{
2990 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
2991 auto in_targetNodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "targetNodeId"_s, true);
2992 auto in_opt_insertBeforeNodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "insertBeforeNodeId"_s, false);
2993 if (m_backendDispatcher->hasProtocolErrors()) {
2994 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.moveTo' can't be processed"_s);
2995 return;
2996 }
2997
2998#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
2999 if (m_alternateDispatcher) {
3000 m_alternateDispatcher->moveTo(protocol_requestId, *in_nodeId, *in_targetNodeId, WTFMove(in_opt_insertBeforeNodeId));
3001 return;
3002 }
3003#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3004
3005 auto result = m_agent->moveTo(*in_nodeId, *in_targetNodeId, WTFMove(in_opt_insertBeforeNodeId));
3006 if (!result) {
3007 ASSERT(!result.error().isEmpty());
3008 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3009 return;
3010 }
3011
3012 auto out_nodeId = WTFMove(result.value());
3013
3014 auto protocol_jsonMessage = JSON::Object::create();
3015 protocol_jsonMessage->setInteger("nodeId"_s, out_nodeId);
3016 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3017}
3018
3019void DOMBackendDispatcher::undo(long protocol_requestId, RefPtr<JSON::Object>&&)
3020{
3021#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3022 if (m_alternateDispatcher) {
3023 m_alternateDispatcher->undo(protocol_requestId);
3024 return;
3025 }
3026#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3027
3028 auto result = m_agent->undo();
3029 if (!result) {
3030 ASSERT(!result.error().isEmpty());
3031 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3032 return;
3033 }
3034
3035 auto protocol_jsonMessage = JSON::Object::create();
3036 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3037}
3038
3039void DOMBackendDispatcher::redo(long protocol_requestId, RefPtr<JSON::Object>&&)
3040{
3041#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3042 if (m_alternateDispatcher) {
3043 m_alternateDispatcher->redo(protocol_requestId);
3044 return;
3045 }
3046#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3047
3048 auto result = m_agent->redo();
3049 if (!result) {
3050 ASSERT(!result.error().isEmpty());
3051 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3052 return;
3053 }
3054
3055 auto protocol_jsonMessage = JSON::Object::create();
3056 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3057}
3058
3059void DOMBackendDispatcher::markUndoableState(long protocol_requestId, RefPtr<JSON::Object>&&)
3060{
3061#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3062 if (m_alternateDispatcher) {
3063 m_alternateDispatcher->markUndoableState(protocol_requestId);
3064 return;
3065 }
3066#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3067
3068 auto result = m_agent->markUndoableState();
3069 if (!result) {
3070 ASSERT(!result.error().isEmpty());
3071 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3072 return;
3073 }
3074
3075 auto protocol_jsonMessage = JSON::Object::create();
3076 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3077}
3078
3079void DOMBackendDispatcher::focus(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3080{
3081 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
3082 if (m_backendDispatcher->hasProtocolErrors()) {
3083 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.focus' can't be processed"_s);
3084 return;
3085 }
3086
3087#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3088 if (m_alternateDispatcher) {
3089 m_alternateDispatcher->focus(protocol_requestId, *in_nodeId);
3090 return;
3091 }
3092#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3093
3094 auto result = m_agent->focus(*in_nodeId);
3095 if (!result) {
3096 ASSERT(!result.error().isEmpty());
3097 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3098 return;
3099 }
3100
3101 auto protocol_jsonMessage = JSON::Object::create();
3102 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3103}
3104
3105void DOMBackendDispatcher::setInspectedNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3106{
3107 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
3108 if (m_backendDispatcher->hasProtocolErrors()) {
3109 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setInspectedNode' can't be processed"_s);
3110 return;
3111 }
3112
3113#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3114 if (m_alternateDispatcher) {
3115 m_alternateDispatcher->setInspectedNode(protocol_requestId, *in_nodeId);
3116 return;
3117 }
3118#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3119
3120 auto result = m_agent->setInspectedNode(*in_nodeId);
3121 if (!result) {
3122 ASSERT(!result.error().isEmpty());
3123 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3124 return;
3125 }
3126
3127 auto protocol_jsonMessage = JSON::Object::create();
3128 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3129}
3130
3131void DOMBackendDispatcher::setAllowEditingUserAgentShadowTrees(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3132{
3133 auto in_allow = m_backendDispatcher->getBoolean(protocol_parameters.get(), "allow"_s, true);
3134 if (m_backendDispatcher->hasProtocolErrors()) {
3135 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOM.setAllowEditingUserAgentShadowTrees' can't be processed"_s);
3136 return;
3137 }
3138
3139#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3140 if (m_alternateDispatcher) {
3141 m_alternateDispatcher->setAllowEditingUserAgentShadowTrees(protocol_requestId, *in_allow);
3142 return;
3143 }
3144#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3145
3146 auto result = m_agent->setAllowEditingUserAgentShadowTrees(*in_allow);
3147 if (!result) {
3148 ASSERT(!result.error().isEmpty());
3149 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3150 return;
3151 }
3152
3153 auto protocol_jsonMessage = JSON::Object::create();
3154 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3155}
3156
3157Ref<DOMDebuggerBackendDispatcher> DOMDebuggerBackendDispatcher::create(BackendDispatcher& backendDispatcher, DOMDebuggerBackendDispatcherHandler* agent)
3158{
3159 return adoptRef(*new DOMDebuggerBackendDispatcher(backendDispatcher, agent));
3160}
3161
3162DOMDebuggerBackendDispatcher::DOMDebuggerBackendDispatcher(BackendDispatcher& backendDispatcher, DOMDebuggerBackendDispatcherHandler* agent)
3163 : SupplementalBackendDispatcher(backendDispatcher)
3164 , m_agent(agent)
3165{
3166 m_backendDispatcher->registerDispatcherForDomain("DOMDebugger"_s, this);
3167}
3168
3169void DOMDebuggerBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
3170{
3171 Ref<DOMDebuggerBackendDispatcher> protect(*this);
3172
3173 auto protocol_parameters = protocol_message->getObject("params"_s);
3174
3175 using CallHandler = void (DOMDebuggerBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
3176 using DispatchMap = HashMap<String, CallHandler>;
3177 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
3178 { "setDOMBreakpoint"_s, &DOMDebuggerBackendDispatcher::setDOMBreakpoint },
3179 { "removeDOMBreakpoint"_s, &DOMDebuggerBackendDispatcher::removeDOMBreakpoint },
3180 { "setEventBreakpoint"_s, &DOMDebuggerBackendDispatcher::setEventBreakpoint },
3181 { "removeEventBreakpoint"_s, &DOMDebuggerBackendDispatcher::removeEventBreakpoint },
3182 { "setURLBreakpoint"_s, &DOMDebuggerBackendDispatcher::setURLBreakpoint },
3183 { "removeURLBreakpoint"_s, &DOMDebuggerBackendDispatcher::removeURLBreakpoint },
3184 });
3185
3186 auto findResult = dispatchMap->find(protocol_method);
3187 if (findResult == dispatchMap->end()) {
3188 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'DOMDebugger."_s, protocol_method, "' was not found"_s));
3189 return;
3190 }
3191
3192 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
3193}
3194
3195void DOMDebuggerBackendDispatcher::setDOMBreakpoint(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3196{
3197 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
3198 auto in_type_json = m_backendDispatcher->getString(protocol_parameters.get(), "type"_s, true);
3199 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
3200 if (m_backendDispatcher->hasProtocolErrors()) {
3201 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.setDOMBreakpoint' can't be processed"_s);
3202 return;
3203 }
3204
3205#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3206 if (m_alternateDispatcher) {
3207 m_alternateDispatcher->setDOMBreakpoint(protocol_requestId, *in_nodeId, in_type_json, WTFMove(in_opt_options));
3208 return;
3209 }
3210#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3211
3212 auto in_type = Protocol::Helpers::parseEnumValueFromString<Protocol::DOMDebugger::DOMBreakpointType>(in_type_json);
3213 if (!in_type) {
3214 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown type: "_s, in_type_json));
3215 return;
3216 }
3217
3218 auto result = m_agent->setDOMBreakpoint(*in_nodeId, *in_type, WTFMove(in_opt_options));
3219 if (!result) {
3220 ASSERT(!result.error().isEmpty());
3221 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3222 return;
3223 }
3224
3225 auto protocol_jsonMessage = JSON::Object::create();
3226 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3227}
3228
3229void DOMDebuggerBackendDispatcher::removeDOMBreakpoint(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3230{
3231 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
3232 auto in_type_json = m_backendDispatcher->getString(protocol_parameters.get(), "type"_s, true);
3233 if (m_backendDispatcher->hasProtocolErrors()) {
3234 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.removeDOMBreakpoint' can't be processed"_s);
3235 return;
3236 }
3237
3238#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3239 if (m_alternateDispatcher) {
3240 m_alternateDispatcher->removeDOMBreakpoint(protocol_requestId, *in_nodeId, in_type_json);
3241 return;
3242 }
3243#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3244
3245 auto in_type = Protocol::Helpers::parseEnumValueFromString<Protocol::DOMDebugger::DOMBreakpointType>(in_type_json);
3246 if (!in_type) {
3247 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown type: "_s, in_type_json));
3248 return;
3249 }
3250
3251 auto result = m_agent->removeDOMBreakpoint(*in_nodeId, *in_type);
3252 if (!result) {
3253 ASSERT(!result.error().isEmpty());
3254 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3255 return;
3256 }
3257
3258 auto protocol_jsonMessage = JSON::Object::create();
3259 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3260}
3261
3262void DOMDebuggerBackendDispatcher::setEventBreakpoint(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3263{
3264 auto in_breakpointType_json = m_backendDispatcher->getString(protocol_parameters.get(), "breakpointType"_s, true);
3265 auto in_opt_eventName = m_backendDispatcher->getString(protocol_parameters.get(), "eventName"_s, false);
3266 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
3267 if (m_backendDispatcher->hasProtocolErrors()) {
3268 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.setEventBreakpoint' can't be processed"_s);
3269 return;
3270 }
3271
3272#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3273 if (m_alternateDispatcher) {
3274 m_alternateDispatcher->setEventBreakpoint(protocol_requestId, in_breakpointType_json, in_opt_eventName, WTFMove(in_opt_options));
3275 return;
3276 }
3277#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3278
3279 auto in_breakpointType = Protocol::Helpers::parseEnumValueFromString<Protocol::DOMDebugger::EventBreakpointType>(in_breakpointType_json);
3280 if (!in_breakpointType) {
3281 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown breakpointType: "_s, in_breakpointType_json));
3282 return;
3283 }
3284
3285 auto result = m_agent->setEventBreakpoint(*in_breakpointType, in_opt_eventName, WTFMove(in_opt_options));
3286 if (!result) {
3287 ASSERT(!result.error().isEmpty());
3288 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3289 return;
3290 }
3291
3292 auto protocol_jsonMessage = JSON::Object::create();
3293 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3294}
3295
3296void DOMDebuggerBackendDispatcher::removeEventBreakpoint(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3297{
3298 auto in_breakpointType_json = m_backendDispatcher->getString(protocol_parameters.get(), "breakpointType"_s, true);
3299 auto in_opt_eventName = m_backendDispatcher->getString(protocol_parameters.get(), "eventName"_s, false);
3300 if (m_backendDispatcher->hasProtocolErrors()) {
3301 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.removeEventBreakpoint' can't be processed"_s);
3302 return;
3303 }
3304
3305#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3306 if (m_alternateDispatcher) {
3307 m_alternateDispatcher->removeEventBreakpoint(protocol_requestId, in_breakpointType_json, in_opt_eventName);
3308 return;
3309 }
3310#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3311
3312 auto in_breakpointType = Protocol::Helpers::parseEnumValueFromString<Protocol::DOMDebugger::EventBreakpointType>(in_breakpointType_json);
3313 if (!in_breakpointType) {
3314 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown breakpointType: "_s, in_breakpointType_json));
3315 return;
3316 }
3317
3318 auto result = m_agent->removeEventBreakpoint(*in_breakpointType, in_opt_eventName);
3319 if (!result) {
3320 ASSERT(!result.error().isEmpty());
3321 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3322 return;
3323 }
3324
3325 auto protocol_jsonMessage = JSON::Object::create();
3326 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3327}
3328
3329void DOMDebuggerBackendDispatcher::setURLBreakpoint(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3330{
3331 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
3332 auto in_opt_isRegex = m_backendDispatcher->getBoolean(protocol_parameters.get(), "isRegex"_s, false);
3333 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
3334 if (m_backendDispatcher->hasProtocolErrors()) {
3335 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.setURLBreakpoint' can't be processed"_s);
3336 return;
3337 }
3338
3339#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3340 if (m_alternateDispatcher) {
3341 m_alternateDispatcher->setURLBreakpoint(protocol_requestId, in_url, WTFMove(in_opt_isRegex), WTFMove(in_opt_options));
3342 return;
3343 }
3344#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3345
3346 auto result = m_agent->setURLBreakpoint(in_url, WTFMove(in_opt_isRegex), WTFMove(in_opt_options));
3347 if (!result) {
3348 ASSERT(!result.error().isEmpty());
3349 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3350 return;
3351 }
3352
3353 auto protocol_jsonMessage = JSON::Object::create();
3354 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3355}
3356
3357void DOMDebuggerBackendDispatcher::removeURLBreakpoint(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3358{
3359 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
3360 auto in_opt_isRegex = m_backendDispatcher->getBoolean(protocol_parameters.get(), "isRegex"_s, false);
3361 if (m_backendDispatcher->hasProtocolErrors()) {
3362 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMDebugger.removeURLBreakpoint' can't be processed"_s);
3363 return;
3364 }
3365
3366#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3367 if (m_alternateDispatcher) {
3368 m_alternateDispatcher->removeURLBreakpoint(protocol_requestId, in_url, WTFMove(in_opt_isRegex));
3369 return;
3370 }
3371#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3372
3373 auto result = m_agent->removeURLBreakpoint(in_url, WTFMove(in_opt_isRegex));
3374 if (!result) {
3375 ASSERT(!result.error().isEmpty());
3376 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3377 return;
3378 }
3379
3380 auto protocol_jsonMessage = JSON::Object::create();
3381 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3382}
3383
3384Ref<DOMStorageBackendDispatcher> DOMStorageBackendDispatcher::create(BackendDispatcher& backendDispatcher, DOMStorageBackendDispatcherHandler* agent)
3385{
3386 return adoptRef(*new DOMStorageBackendDispatcher(backendDispatcher, agent));
3387}
3388
3389DOMStorageBackendDispatcher::DOMStorageBackendDispatcher(BackendDispatcher& backendDispatcher, DOMStorageBackendDispatcherHandler* agent)
3390 : SupplementalBackendDispatcher(backendDispatcher)
3391 , m_agent(agent)
3392{
3393 m_backendDispatcher->registerDispatcherForDomain("DOMStorage"_s, this);
3394}
3395
3396void DOMStorageBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
3397{
3398 Ref<DOMStorageBackendDispatcher> protect(*this);
3399
3400 auto protocol_parameters = protocol_message->getObject("params"_s);
3401
3402 using CallHandler = void (DOMStorageBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
3403 using DispatchMap = HashMap<String, CallHandler>;
3404 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
3405 { "enable"_s, &DOMStorageBackendDispatcher::enable },
3406 { "disable"_s, &DOMStorageBackendDispatcher::disable },
3407 { "getDOMStorageItems"_s, &DOMStorageBackendDispatcher::getDOMStorageItems },
3408 { "setDOMStorageItem"_s, &DOMStorageBackendDispatcher::setDOMStorageItem },
3409 { "removeDOMStorageItem"_s, &DOMStorageBackendDispatcher::removeDOMStorageItem },
3410 { "clearDOMStorageItems"_s, &DOMStorageBackendDispatcher::clearDOMStorageItems },
3411 });
3412
3413 auto findResult = dispatchMap->find(protocol_method);
3414 if (findResult == dispatchMap->end()) {
3415 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'DOMStorage."_s, protocol_method, "' was not found"_s));
3416 return;
3417 }
3418
3419 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
3420}
3421
3422void DOMStorageBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
3423{
3424#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3425 if (m_alternateDispatcher) {
3426 m_alternateDispatcher->enable(protocol_requestId);
3427 return;
3428 }
3429#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3430
3431 auto result = m_agent->enable();
3432 if (!result) {
3433 ASSERT(!result.error().isEmpty());
3434 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3435 return;
3436 }
3437
3438 auto protocol_jsonMessage = JSON::Object::create();
3439 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3440}
3441
3442void DOMStorageBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
3443{
3444#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3445 if (m_alternateDispatcher) {
3446 m_alternateDispatcher->disable(protocol_requestId);
3447 return;
3448 }
3449#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3450
3451 auto result = m_agent->disable();
3452 if (!result) {
3453 ASSERT(!result.error().isEmpty());
3454 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3455 return;
3456 }
3457
3458 auto protocol_jsonMessage = JSON::Object::create();
3459 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3460}
3461
3462void DOMStorageBackendDispatcher::getDOMStorageItems(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3463{
3464 auto in_storageId = m_backendDispatcher->getObject(protocol_parameters.get(), "storageId"_s, true);
3465 if (m_backendDispatcher->hasProtocolErrors()) {
3466 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMStorage.getDOMStorageItems' can't be processed"_s);
3467 return;
3468 }
3469
3470#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3471 if (m_alternateDispatcher) {
3472 m_alternateDispatcher->getDOMStorageItems(protocol_requestId, in_storageId.releaseNonNull());
3473 return;
3474 }
3475#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3476
3477 auto result = m_agent->getDOMStorageItems(in_storageId.releaseNonNull());
3478 if (!result) {
3479 ASSERT(!result.error().isEmpty());
3480 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3481 return;
3482 }
3483
3484 auto out_entries = WTFMove(result.value());
3485
3486 auto protocol_jsonMessage = JSON::Object::create();
3487 protocol_jsonMessage->setArray("entries"_s, WTFMove(out_entries));
3488 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3489}
3490
3491void DOMStorageBackendDispatcher::setDOMStorageItem(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3492{
3493 auto in_storageId = m_backendDispatcher->getObject(protocol_parameters.get(), "storageId"_s, true);
3494 auto in_key = m_backendDispatcher->getString(protocol_parameters.get(), "key"_s, true);
3495 auto in_value = m_backendDispatcher->getString(protocol_parameters.get(), "value"_s, true);
3496 if (m_backendDispatcher->hasProtocolErrors()) {
3497 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMStorage.setDOMStorageItem' can't be processed"_s);
3498 return;
3499 }
3500
3501#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3502 if (m_alternateDispatcher) {
3503 m_alternateDispatcher->setDOMStorageItem(protocol_requestId, in_storageId.releaseNonNull(), in_key, in_value);
3504 return;
3505 }
3506#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3507
3508 auto result = m_agent->setDOMStorageItem(in_storageId.releaseNonNull(), in_key, in_value);
3509 if (!result) {
3510 ASSERT(!result.error().isEmpty());
3511 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3512 return;
3513 }
3514
3515 auto protocol_jsonMessage = JSON::Object::create();
3516 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3517}
3518
3519void DOMStorageBackendDispatcher::removeDOMStorageItem(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3520{
3521 auto in_storageId = m_backendDispatcher->getObject(protocol_parameters.get(), "storageId"_s, true);
3522 auto in_key = m_backendDispatcher->getString(protocol_parameters.get(), "key"_s, true);
3523 if (m_backendDispatcher->hasProtocolErrors()) {
3524 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMStorage.removeDOMStorageItem' can't be processed"_s);
3525 return;
3526 }
3527
3528#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3529 if (m_alternateDispatcher) {
3530 m_alternateDispatcher->removeDOMStorageItem(protocol_requestId, in_storageId.releaseNonNull(), in_key);
3531 return;
3532 }
3533#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3534
3535 auto result = m_agent->removeDOMStorageItem(in_storageId.releaseNonNull(), in_key);
3536 if (!result) {
3537 ASSERT(!result.error().isEmpty());
3538 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3539 return;
3540 }
3541
3542 auto protocol_jsonMessage = JSON::Object::create();
3543 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3544}
3545
3546void DOMStorageBackendDispatcher::clearDOMStorageItems(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3547{
3548 auto in_storageId = m_backendDispatcher->getObject(protocol_parameters.get(), "storageId"_s, true);
3549 if (m_backendDispatcher->hasProtocolErrors()) {
3550 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'DOMStorage.clearDOMStorageItems' can't be processed"_s);
3551 return;
3552 }
3553
3554#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3555 if (m_alternateDispatcher) {
3556 m_alternateDispatcher->clearDOMStorageItems(protocol_requestId, in_storageId.releaseNonNull());
3557 return;
3558 }
3559#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3560
3561 auto result = m_agent->clearDOMStorageItems(in_storageId.releaseNonNull());
3562 if (!result) {
3563 ASSERT(!result.error().isEmpty());
3564 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3565 return;
3566 }
3567
3568 auto protocol_jsonMessage = JSON::Object::create();
3569 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3570}
3571
3572Ref<DatabaseBackendDispatcher> DatabaseBackendDispatcher::create(BackendDispatcher& backendDispatcher, DatabaseBackendDispatcherHandler* agent)
3573{
3574 return adoptRef(*new DatabaseBackendDispatcher(backendDispatcher, agent));
3575}
3576
3577DatabaseBackendDispatcher::DatabaseBackendDispatcher(BackendDispatcher& backendDispatcher, DatabaseBackendDispatcherHandler* agent)
3578 : SupplementalBackendDispatcher(backendDispatcher)
3579 , m_agent(agent)
3580{
3581 m_backendDispatcher->registerDispatcherForDomain("Database"_s, this);
3582}
3583
3584void DatabaseBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
3585{
3586 Ref<DatabaseBackendDispatcher> protect(*this);
3587
3588 auto protocol_parameters = protocol_message->getObject("params"_s);
3589
3590 if (protocol_method == "enable"_s) {
3591 enable(protocol_requestId, WTFMove(protocol_parameters));
3592 return;
3593 }
3594 if (protocol_method == "disable"_s) {
3595 disable(protocol_requestId, WTFMove(protocol_parameters));
3596 return;
3597 }
3598 if (protocol_method == "getDatabaseTableNames"_s) {
3599 getDatabaseTableNames(protocol_requestId, WTFMove(protocol_parameters));
3600 return;
3601 }
3602 if (protocol_method == "executeSQL"_s) {
3603 executeSQL(protocol_requestId, WTFMove(protocol_parameters));
3604 return;
3605 }
3606
3607 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Database."_s, protocol_method, "' was not found"_s));
3608}
3609
3610void DatabaseBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
3611{
3612#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3613 if (m_alternateDispatcher) {
3614 m_alternateDispatcher->enable(protocol_requestId);
3615 return;
3616 }
3617#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3618
3619 auto result = m_agent->enable();
3620 if (!result) {
3621 ASSERT(!result.error().isEmpty());
3622 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3623 return;
3624 }
3625
3626 auto protocol_jsonMessage = JSON::Object::create();
3627 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3628}
3629
3630void DatabaseBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
3631{
3632#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3633 if (m_alternateDispatcher) {
3634 m_alternateDispatcher->disable(protocol_requestId);
3635 return;
3636 }
3637#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3638
3639 auto result = m_agent->disable();
3640 if (!result) {
3641 ASSERT(!result.error().isEmpty());
3642 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3643 return;
3644 }
3645
3646 auto protocol_jsonMessage = JSON::Object::create();
3647 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3648}
3649
3650void DatabaseBackendDispatcher::getDatabaseTableNames(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3651{
3652 auto in_databaseId = m_backendDispatcher->getString(protocol_parameters.get(), "databaseId"_s, true);
3653 if (m_backendDispatcher->hasProtocolErrors()) {
3654 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Database.getDatabaseTableNames' can't be processed"_s);
3655 return;
3656 }
3657
3658#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3659 if (m_alternateDispatcher) {
3660 m_alternateDispatcher->getDatabaseTableNames(protocol_requestId, in_databaseId);
3661 return;
3662 }
3663#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3664
3665 auto result = m_agent->getDatabaseTableNames(in_databaseId);
3666 if (!result) {
3667 ASSERT(!result.error().isEmpty());
3668 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3669 return;
3670 }
3671
3672 auto out_tableNames = WTFMove(result.value());
3673
3674 auto protocol_jsonMessage = JSON::Object::create();
3675 protocol_jsonMessage->setArray("tableNames"_s, WTFMove(out_tableNames));
3676 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3677}
3678
3679DatabaseBackendDispatcherHandler::ExecuteSQLCallback::ExecuteSQLCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { }
3680
3681void DatabaseBackendDispatcherHandler::ExecuteSQLCallback::sendSuccess(RefPtr<JSON::ArrayOf<String>>&& opt_columnNames, RefPtr<JSON::ArrayOf<JSON::Value>>&& opt_values, RefPtr<Protocol::Database::Error>&& opt_sqlError)
3682{
3683 auto protocol_jsonMessage = JSON::Object::create();
3684 if (!!opt_columnNames)
3685 protocol_jsonMessage->setArray("columnNames"_s, opt_columnNames.releaseNonNull());
3686 if (!!opt_values)
3687 protocol_jsonMessage->setArray("values"_s, opt_values.releaseNonNull());
3688 if (!!opt_sqlError)
3689 protocol_jsonMessage->setObject("sqlError"_s, opt_sqlError.releaseNonNull());
3690 CallbackBase::sendSuccess(WTFMove(protocol_jsonMessage));
3691}
3692
3693void DatabaseBackendDispatcher::executeSQL(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3694{
3695 auto in_databaseId = m_backendDispatcher->getString(protocol_parameters.get(), "databaseId"_s, true);
3696 auto in_query = m_backendDispatcher->getString(protocol_parameters.get(), "query"_s, true);
3697 if (m_backendDispatcher->hasProtocolErrors()) {
3698 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Database.executeSQL' can't be processed"_s);
3699 return;
3700 }
3701
3702#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3703 if (m_alternateDispatcher) {
3704 m_alternateDispatcher->executeSQL(protocol_requestId, in_databaseId, in_query);
3705 return;
3706 }
3707#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3708
3709 m_agent->executeSQL(in_databaseId, in_query, adoptRef(*new DatabaseBackendDispatcherHandler::ExecuteSQLCallback(m_backendDispatcher.copyRef(), protocol_requestId)));
3710}
3711
3712Ref<DebuggerBackendDispatcher> DebuggerBackendDispatcher::create(BackendDispatcher& backendDispatcher, DebuggerBackendDispatcherHandler* agent)
3713{
3714 return adoptRef(*new DebuggerBackendDispatcher(backendDispatcher, agent));
3715}
3716
3717DebuggerBackendDispatcher::DebuggerBackendDispatcher(BackendDispatcher& backendDispatcher, DebuggerBackendDispatcherHandler* agent)
3718 : SupplementalBackendDispatcher(backendDispatcher)
3719 , m_agent(agent)
3720{
3721 m_backendDispatcher->registerDispatcherForDomain("Debugger"_s, this);
3722}
3723
3724void DebuggerBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
3725{
3726 Ref<DebuggerBackendDispatcher> protect(*this);
3727
3728 auto protocol_parameters = protocol_message->getObject("params"_s);
3729
3730 using CallHandler = void (DebuggerBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
3731 using DispatchMap = HashMap<String, CallHandler>;
3732 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
3733 { "enable"_s, &DebuggerBackendDispatcher::enable },
3734 { "disable"_s, &DebuggerBackendDispatcher::disable },
3735 { "setAsyncStackTraceDepth"_s, &DebuggerBackendDispatcher::setAsyncStackTraceDepth },
3736 { "setBreakpointsActive"_s, &DebuggerBackendDispatcher::setBreakpointsActive },
3737 { "setBreakpointByUrl"_s, &DebuggerBackendDispatcher::setBreakpointByUrl },
3738 { "setBreakpoint"_s, &DebuggerBackendDispatcher::setBreakpoint },
3739 { "removeBreakpoint"_s, &DebuggerBackendDispatcher::removeBreakpoint },
3740 { "continueUntilNextRunLoop"_s, &DebuggerBackendDispatcher::continueUntilNextRunLoop },
3741 { "continueToLocation"_s, &DebuggerBackendDispatcher::continueToLocation },
3742 { "stepNext"_s, &DebuggerBackendDispatcher::stepNext },
3743 { "stepOver"_s, &DebuggerBackendDispatcher::stepOver },
3744 { "stepInto"_s, &DebuggerBackendDispatcher::stepInto },
3745 { "stepOut"_s, &DebuggerBackendDispatcher::stepOut },
3746 { "pause"_s, &DebuggerBackendDispatcher::pause },
3747 { "resume"_s, &DebuggerBackendDispatcher::resume },
3748 { "searchInContent"_s, &DebuggerBackendDispatcher::searchInContent },
3749 { "getScriptSource"_s, &DebuggerBackendDispatcher::getScriptSource },
3750 { "getFunctionDetails"_s, &DebuggerBackendDispatcher::getFunctionDetails },
3751 { "setPauseOnDebuggerStatements"_s, &DebuggerBackendDispatcher::setPauseOnDebuggerStatements },
3752 { "setPauseOnExceptions"_s, &DebuggerBackendDispatcher::setPauseOnExceptions },
3753 { "setPauseOnAssertions"_s, &DebuggerBackendDispatcher::setPauseOnAssertions },
3754 { "setPauseOnMicrotasks"_s, &DebuggerBackendDispatcher::setPauseOnMicrotasks },
3755 { "setPauseForInternalScripts"_s, &DebuggerBackendDispatcher::setPauseForInternalScripts },
3756 { "evaluateOnCallFrame"_s, &DebuggerBackendDispatcher::evaluateOnCallFrame },
3757 { "setShouldBlackboxURL"_s, &DebuggerBackendDispatcher::setShouldBlackboxURL },
3758 });
3759
3760 auto findResult = dispatchMap->find(protocol_method);
3761 if (findResult == dispatchMap->end()) {
3762 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Debugger."_s, protocol_method, "' was not found"_s));
3763 return;
3764 }
3765
3766 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
3767}
3768
3769void DebuggerBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
3770{
3771#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3772 if (m_alternateDispatcher) {
3773 m_alternateDispatcher->enable(protocol_requestId);
3774 return;
3775 }
3776#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3777
3778 auto result = m_agent->enable();
3779 if (!result) {
3780 ASSERT(!result.error().isEmpty());
3781 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3782 return;
3783 }
3784
3785 auto protocol_jsonMessage = JSON::Object::create();
3786 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3787}
3788
3789void DebuggerBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
3790{
3791#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3792 if (m_alternateDispatcher) {
3793 m_alternateDispatcher->disable(protocol_requestId);
3794 return;
3795 }
3796#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3797
3798 auto result = m_agent->disable();
3799 if (!result) {
3800 ASSERT(!result.error().isEmpty());
3801 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3802 return;
3803 }
3804
3805 auto protocol_jsonMessage = JSON::Object::create();
3806 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3807}
3808
3809void DebuggerBackendDispatcher::setAsyncStackTraceDepth(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3810{
3811 auto in_depth = m_backendDispatcher->getInteger(protocol_parameters.get(), "depth"_s, true);
3812 if (m_backendDispatcher->hasProtocolErrors()) {
3813 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setAsyncStackTraceDepth' can't be processed"_s);
3814 return;
3815 }
3816
3817#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3818 if (m_alternateDispatcher) {
3819 m_alternateDispatcher->setAsyncStackTraceDepth(protocol_requestId, *in_depth);
3820 return;
3821 }
3822#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3823
3824 auto result = m_agent->setAsyncStackTraceDepth(*in_depth);
3825 if (!result) {
3826 ASSERT(!result.error().isEmpty());
3827 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3828 return;
3829 }
3830
3831 auto protocol_jsonMessage = JSON::Object::create();
3832 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3833}
3834
3835void DebuggerBackendDispatcher::setBreakpointsActive(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3836{
3837 auto in_active = m_backendDispatcher->getBoolean(protocol_parameters.get(), "active"_s, true);
3838 if (m_backendDispatcher->hasProtocolErrors()) {
3839 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setBreakpointsActive' can't be processed"_s);
3840 return;
3841 }
3842
3843#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3844 if (m_alternateDispatcher) {
3845 m_alternateDispatcher->setBreakpointsActive(protocol_requestId, *in_active);
3846 return;
3847 }
3848#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3849
3850 auto result = m_agent->setBreakpointsActive(*in_active);
3851 if (!result) {
3852 ASSERT(!result.error().isEmpty());
3853 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3854 return;
3855 }
3856
3857 auto protocol_jsonMessage = JSON::Object::create();
3858 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3859}
3860
3861void DebuggerBackendDispatcher::setBreakpointByUrl(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3862{
3863 auto in_lineNumber = m_backendDispatcher->getInteger(protocol_parameters.get(), "lineNumber"_s, true);
3864 auto in_opt_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, false);
3865 auto in_opt_urlRegex = m_backendDispatcher->getString(protocol_parameters.get(), "urlRegex"_s, false);
3866 auto in_opt_columnNumber = m_backendDispatcher->getInteger(protocol_parameters.get(), "columnNumber"_s, false);
3867 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
3868 if (m_backendDispatcher->hasProtocolErrors()) {
3869 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setBreakpointByUrl' can't be processed"_s);
3870 return;
3871 }
3872
3873#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3874 if (m_alternateDispatcher) {
3875 m_alternateDispatcher->setBreakpointByUrl(protocol_requestId, *in_lineNumber, in_opt_url, in_opt_urlRegex, WTFMove(in_opt_columnNumber), WTFMove(in_opt_options));
3876 return;
3877 }
3878#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3879
3880 auto result = m_agent->setBreakpointByUrl(*in_lineNumber, in_opt_url, in_opt_urlRegex, WTFMove(in_opt_columnNumber), WTFMove(in_opt_options));
3881 if (!result) {
3882 ASSERT(!result.error().isEmpty());
3883 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3884 return;
3885 }
3886
3887 auto [out_breakpointId, out_locations] = WTFMove(result.value());
3888
3889 auto protocol_jsonMessage = JSON::Object::create();
3890 protocol_jsonMessage->setString("breakpointId"_s, out_breakpointId);
3891 protocol_jsonMessage->setArray("locations"_s, WTFMove(out_locations));
3892 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3893}
3894
3895void DebuggerBackendDispatcher::setBreakpoint(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3896{
3897 auto in_location = m_backendDispatcher->getObject(protocol_parameters.get(), "location"_s, true);
3898 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
3899 if (m_backendDispatcher->hasProtocolErrors()) {
3900 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setBreakpoint' can't be processed"_s);
3901 return;
3902 }
3903
3904#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3905 if (m_alternateDispatcher) {
3906 m_alternateDispatcher->setBreakpoint(protocol_requestId, in_location.releaseNonNull(), WTFMove(in_opt_options));
3907 return;
3908 }
3909#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3910
3911 auto result = m_agent->setBreakpoint(in_location.releaseNonNull(), WTFMove(in_opt_options));
3912 if (!result) {
3913 ASSERT(!result.error().isEmpty());
3914 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3915 return;
3916 }
3917
3918 auto [out_breakpointId, out_actualLocation] = WTFMove(result.value());
3919
3920 auto protocol_jsonMessage = JSON::Object::create();
3921 protocol_jsonMessage->setString("breakpointId"_s, out_breakpointId);
3922 protocol_jsonMessage->setObject("actualLocation"_s, WTFMove(out_actualLocation));
3923 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3924}
3925
3926void DebuggerBackendDispatcher::removeBreakpoint(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3927{
3928 auto in_breakpointId = m_backendDispatcher->getString(protocol_parameters.get(), "breakpointId"_s, true);
3929 if (m_backendDispatcher->hasProtocolErrors()) {
3930 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.removeBreakpoint' can't be processed"_s);
3931 return;
3932 }
3933
3934#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3935 if (m_alternateDispatcher) {
3936 m_alternateDispatcher->removeBreakpoint(protocol_requestId, in_breakpointId);
3937 return;
3938 }
3939#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3940
3941 auto result = m_agent->removeBreakpoint(in_breakpointId);
3942 if (!result) {
3943 ASSERT(!result.error().isEmpty());
3944 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3945 return;
3946 }
3947
3948 auto protocol_jsonMessage = JSON::Object::create();
3949 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3950}
3951
3952void DebuggerBackendDispatcher::continueUntilNextRunLoop(long protocol_requestId, RefPtr<JSON::Object>&&)
3953{
3954#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3955 if (m_alternateDispatcher) {
3956 m_alternateDispatcher->continueUntilNextRunLoop(protocol_requestId);
3957 return;
3958 }
3959#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3960
3961 auto result = m_agent->continueUntilNextRunLoop();
3962 if (!result) {
3963 ASSERT(!result.error().isEmpty());
3964 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3965 return;
3966 }
3967
3968 auto protocol_jsonMessage = JSON::Object::create();
3969 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3970}
3971
3972void DebuggerBackendDispatcher::continueToLocation(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
3973{
3974 auto in_location = m_backendDispatcher->getObject(protocol_parameters.get(), "location"_s, true);
3975 if (m_backendDispatcher->hasProtocolErrors()) {
3976 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.continueToLocation' can't be processed"_s);
3977 return;
3978 }
3979
3980#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3981 if (m_alternateDispatcher) {
3982 m_alternateDispatcher->continueToLocation(protocol_requestId, in_location.releaseNonNull());
3983 return;
3984 }
3985#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
3986
3987 auto result = m_agent->continueToLocation(in_location.releaseNonNull());
3988 if (!result) {
3989 ASSERT(!result.error().isEmpty());
3990 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
3991 return;
3992 }
3993
3994 auto protocol_jsonMessage = JSON::Object::create();
3995 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
3996}
3997
3998void DebuggerBackendDispatcher::stepNext(long protocol_requestId, RefPtr<JSON::Object>&&)
3999{
4000#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4001 if (m_alternateDispatcher) {
4002 m_alternateDispatcher->stepNext(protocol_requestId);
4003 return;
4004 }
4005#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4006
4007 auto result = m_agent->stepNext();
4008 if (!result) {
4009 ASSERT(!result.error().isEmpty());
4010 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4011 return;
4012 }
4013
4014 auto protocol_jsonMessage = JSON::Object::create();
4015 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4016}
4017
4018void DebuggerBackendDispatcher::stepOver(long protocol_requestId, RefPtr<JSON::Object>&&)
4019{
4020#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4021 if (m_alternateDispatcher) {
4022 m_alternateDispatcher->stepOver(protocol_requestId);
4023 return;
4024 }
4025#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4026
4027 auto result = m_agent->stepOver();
4028 if (!result) {
4029 ASSERT(!result.error().isEmpty());
4030 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4031 return;
4032 }
4033
4034 auto protocol_jsonMessage = JSON::Object::create();
4035 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4036}
4037
4038void DebuggerBackendDispatcher::stepInto(long protocol_requestId, RefPtr<JSON::Object>&&)
4039{
4040#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4041 if (m_alternateDispatcher) {
4042 m_alternateDispatcher->stepInto(protocol_requestId);
4043 return;
4044 }
4045#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4046
4047 auto result = m_agent->stepInto();
4048 if (!result) {
4049 ASSERT(!result.error().isEmpty());
4050 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4051 return;
4052 }
4053
4054 auto protocol_jsonMessage = JSON::Object::create();
4055 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4056}
4057
4058void DebuggerBackendDispatcher::stepOut(long protocol_requestId, RefPtr<JSON::Object>&&)
4059{
4060#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4061 if (m_alternateDispatcher) {
4062 m_alternateDispatcher->stepOut(protocol_requestId);
4063 return;
4064 }
4065#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4066
4067 auto result = m_agent->stepOut();
4068 if (!result) {
4069 ASSERT(!result.error().isEmpty());
4070 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4071 return;
4072 }
4073
4074 auto protocol_jsonMessage = JSON::Object::create();
4075 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4076}
4077
4078void DebuggerBackendDispatcher::pause(long protocol_requestId, RefPtr<JSON::Object>&&)
4079{
4080#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4081 if (m_alternateDispatcher) {
4082 m_alternateDispatcher->pause(protocol_requestId);
4083 return;
4084 }
4085#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4086
4087 auto result = m_agent->pause();
4088 if (!result) {
4089 ASSERT(!result.error().isEmpty());
4090 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4091 return;
4092 }
4093
4094 auto protocol_jsonMessage = JSON::Object::create();
4095 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4096}
4097
4098void DebuggerBackendDispatcher::resume(long protocol_requestId, RefPtr<JSON::Object>&&)
4099{
4100#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4101 if (m_alternateDispatcher) {
4102 m_alternateDispatcher->resume(protocol_requestId);
4103 return;
4104 }
4105#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4106
4107 auto result = m_agent->resume();
4108 if (!result) {
4109 ASSERT(!result.error().isEmpty());
4110 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4111 return;
4112 }
4113
4114 auto protocol_jsonMessage = JSON::Object::create();
4115 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4116}
4117
4118void DebuggerBackendDispatcher::searchInContent(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4119{
4120 auto in_scriptId = m_backendDispatcher->getString(protocol_parameters.get(), "scriptId"_s, true);
4121 auto in_query = m_backendDispatcher->getString(protocol_parameters.get(), "query"_s, true);
4122 auto in_opt_caseSensitive = m_backendDispatcher->getBoolean(protocol_parameters.get(), "caseSensitive"_s, false);
4123 auto in_opt_isRegex = m_backendDispatcher->getBoolean(protocol_parameters.get(), "isRegex"_s, false);
4124 if (m_backendDispatcher->hasProtocolErrors()) {
4125 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.searchInContent' can't be processed"_s);
4126 return;
4127 }
4128
4129#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4130 if (m_alternateDispatcher) {
4131 m_alternateDispatcher->searchInContent(protocol_requestId, in_scriptId, in_query, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
4132 return;
4133 }
4134#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4135
4136 auto result = m_agent->searchInContent(in_scriptId, in_query, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
4137 if (!result) {
4138 ASSERT(!result.error().isEmpty());
4139 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4140 return;
4141 }
4142
4143 auto out_result = WTFMove(result.value());
4144
4145 auto protocol_jsonMessage = JSON::Object::create();
4146 protocol_jsonMessage->setArray("result"_s, WTFMove(out_result));
4147 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4148}
4149
4150void DebuggerBackendDispatcher::getScriptSource(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4151{
4152 auto in_scriptId = m_backendDispatcher->getString(protocol_parameters.get(), "scriptId"_s, true);
4153 if (m_backendDispatcher->hasProtocolErrors()) {
4154 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.getScriptSource' can't be processed"_s);
4155 return;
4156 }
4157
4158#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4159 if (m_alternateDispatcher) {
4160 m_alternateDispatcher->getScriptSource(protocol_requestId, in_scriptId);
4161 return;
4162 }
4163#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4164
4165 auto result = m_agent->getScriptSource(in_scriptId);
4166 if (!result) {
4167 ASSERT(!result.error().isEmpty());
4168 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4169 return;
4170 }
4171
4172 auto out_scriptSource = WTFMove(result.value());
4173
4174 auto protocol_jsonMessage = JSON::Object::create();
4175 protocol_jsonMessage->setString("scriptSource"_s, out_scriptSource);
4176 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4177}
4178
4179void DebuggerBackendDispatcher::getFunctionDetails(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4180{
4181 auto in_functionId = m_backendDispatcher->getString(protocol_parameters.get(), "functionId"_s, true);
4182 if (m_backendDispatcher->hasProtocolErrors()) {
4183 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.getFunctionDetails' can't be processed"_s);
4184 return;
4185 }
4186
4187#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4188 if (m_alternateDispatcher) {
4189 m_alternateDispatcher->getFunctionDetails(protocol_requestId, in_functionId);
4190 return;
4191 }
4192#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4193
4194 auto result = m_agent->getFunctionDetails(in_functionId);
4195 if (!result) {
4196 ASSERT(!result.error().isEmpty());
4197 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4198 return;
4199 }
4200
4201 auto out_details = WTFMove(result.value());
4202
4203 auto protocol_jsonMessage = JSON::Object::create();
4204 protocol_jsonMessage->setObject("details"_s, WTFMove(out_details));
4205 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4206}
4207
4208void DebuggerBackendDispatcher::setPauseOnDebuggerStatements(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4209{
4210 auto in_enabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "enabled"_s, true);
4211 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
4212 if (m_backendDispatcher->hasProtocolErrors()) {
4213 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setPauseOnDebuggerStatements' can't be processed"_s);
4214 return;
4215 }
4216
4217#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4218 if (m_alternateDispatcher) {
4219 m_alternateDispatcher->setPauseOnDebuggerStatements(protocol_requestId, *in_enabled, WTFMove(in_opt_options));
4220 return;
4221 }
4222#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4223
4224 auto result = m_agent->setPauseOnDebuggerStatements(*in_enabled, WTFMove(in_opt_options));
4225 if (!result) {
4226 ASSERT(!result.error().isEmpty());
4227 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4228 return;
4229 }
4230
4231 auto protocol_jsonMessage = JSON::Object::create();
4232 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4233}
4234
4235void DebuggerBackendDispatcher::setPauseOnExceptions(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4236{
4237 auto in_state = m_backendDispatcher->getString(protocol_parameters.get(), "state"_s, true);
4238 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
4239 if (m_backendDispatcher->hasProtocolErrors()) {
4240 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setPauseOnExceptions' can't be processed"_s);
4241 return;
4242 }
4243
4244#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4245 if (m_alternateDispatcher) {
4246 m_alternateDispatcher->setPauseOnExceptions(protocol_requestId, in_state, WTFMove(in_opt_options));
4247 return;
4248 }
4249#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4250
4251 auto result = m_agent->setPauseOnExceptions(in_state, WTFMove(in_opt_options));
4252 if (!result) {
4253 ASSERT(!result.error().isEmpty());
4254 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4255 return;
4256 }
4257
4258 auto protocol_jsonMessage = JSON::Object::create();
4259 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4260}
4261
4262void DebuggerBackendDispatcher::setPauseOnAssertions(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4263{
4264 auto in_enabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "enabled"_s, true);
4265 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
4266 if (m_backendDispatcher->hasProtocolErrors()) {
4267 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setPauseOnAssertions' can't be processed"_s);
4268 return;
4269 }
4270
4271#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4272 if (m_alternateDispatcher) {
4273 m_alternateDispatcher->setPauseOnAssertions(protocol_requestId, *in_enabled, WTFMove(in_opt_options));
4274 return;
4275 }
4276#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4277
4278 auto result = m_agent->setPauseOnAssertions(*in_enabled, WTFMove(in_opt_options));
4279 if (!result) {
4280 ASSERT(!result.error().isEmpty());
4281 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4282 return;
4283 }
4284
4285 auto protocol_jsonMessage = JSON::Object::create();
4286 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4287}
4288
4289void DebuggerBackendDispatcher::setPauseOnMicrotasks(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4290{
4291 auto in_enabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "enabled"_s, true);
4292 auto in_opt_options = m_backendDispatcher->getObject(protocol_parameters.get(), "options"_s, false);
4293 if (m_backendDispatcher->hasProtocolErrors()) {
4294 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setPauseOnMicrotasks' can't be processed"_s);
4295 return;
4296 }
4297
4298#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4299 if (m_alternateDispatcher) {
4300 m_alternateDispatcher->setPauseOnMicrotasks(protocol_requestId, *in_enabled, WTFMove(in_opt_options));
4301 return;
4302 }
4303#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4304
4305 auto result = m_agent->setPauseOnMicrotasks(*in_enabled, WTFMove(in_opt_options));
4306 if (!result) {
4307 ASSERT(!result.error().isEmpty());
4308 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4309 return;
4310 }
4311
4312 auto protocol_jsonMessage = JSON::Object::create();
4313 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4314}
4315
4316void DebuggerBackendDispatcher::setPauseForInternalScripts(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4317{
4318 auto in_shouldPause = m_backendDispatcher->getBoolean(protocol_parameters.get(), "shouldPause"_s, true);
4319 if (m_backendDispatcher->hasProtocolErrors()) {
4320 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setPauseForInternalScripts' can't be processed"_s);
4321 return;
4322 }
4323
4324#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4325 if (m_alternateDispatcher) {
4326 m_alternateDispatcher->setPauseForInternalScripts(protocol_requestId, *in_shouldPause);
4327 return;
4328 }
4329#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4330
4331 auto result = m_agent->setPauseForInternalScripts(*in_shouldPause);
4332 if (!result) {
4333 ASSERT(!result.error().isEmpty());
4334 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4335 return;
4336 }
4337
4338 auto protocol_jsonMessage = JSON::Object::create();
4339 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4340}
4341
4342void DebuggerBackendDispatcher::evaluateOnCallFrame(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4343{
4344 auto in_callFrameId = m_backendDispatcher->getString(protocol_parameters.get(), "callFrameId"_s, true);
4345 auto in_expression = m_backendDispatcher->getString(protocol_parameters.get(), "expression"_s, true);
4346 auto in_opt_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, false);
4347 auto in_opt_includeCommandLineAPI = m_backendDispatcher->getBoolean(protocol_parameters.get(), "includeCommandLineAPI"_s, false);
4348 auto in_opt_doNotPauseOnExceptionsAndMuteConsole = m_backendDispatcher->getBoolean(protocol_parameters.get(), "doNotPauseOnExceptionsAndMuteConsole"_s, false);
4349 auto in_opt_returnByValue = m_backendDispatcher->getBoolean(protocol_parameters.get(), "returnByValue"_s, false);
4350 auto in_opt_generatePreview = m_backendDispatcher->getBoolean(protocol_parameters.get(), "generatePreview"_s, false);
4351 auto in_opt_saveResult = m_backendDispatcher->getBoolean(protocol_parameters.get(), "saveResult"_s, false);
4352 auto in_opt_emulateUserGesture = m_backendDispatcher->getBoolean(protocol_parameters.get(), "emulateUserGesture"_s, false);
4353 if (m_backendDispatcher->hasProtocolErrors()) {
4354 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.evaluateOnCallFrame' can't be processed"_s);
4355 return;
4356 }
4357
4358#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4359 if (m_alternateDispatcher) {
4360 m_alternateDispatcher->evaluateOnCallFrame(protocol_requestId, in_callFrameId, in_expression, in_opt_objectGroup, WTFMove(in_opt_includeCommandLineAPI), WTFMove(in_opt_doNotPauseOnExceptionsAndMuteConsole), WTFMove(in_opt_returnByValue), WTFMove(in_opt_generatePreview), WTFMove(in_opt_saveResult), WTFMove(in_opt_emulateUserGesture));
4361 return;
4362 }
4363#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4364
4365 auto result = m_agent->evaluateOnCallFrame(in_callFrameId, in_expression, in_opt_objectGroup, WTFMove(in_opt_includeCommandLineAPI), WTFMove(in_opt_doNotPauseOnExceptionsAndMuteConsole), WTFMove(in_opt_returnByValue), WTFMove(in_opt_generatePreview), WTFMove(in_opt_saveResult), WTFMove(in_opt_emulateUserGesture));
4366 if (!result) {
4367 ASSERT(!result.error().isEmpty());
4368 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4369 return;
4370 }
4371
4372 auto [out_result, out_opt_wasThrown, out_opt_savedResultIndex] = WTFMove(result.value());
4373
4374 auto protocol_jsonMessage = JSON::Object::create();
4375 protocol_jsonMessage->setObject("result"_s, WTFMove(out_result));
4376 if (!!out_opt_wasThrown)
4377 protocol_jsonMessage->setBoolean("wasThrown"_s, *out_opt_wasThrown);
4378 if (!!out_opt_savedResultIndex)
4379 protocol_jsonMessage->setInteger("savedResultIndex"_s, *out_opt_savedResultIndex);
4380 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4381}
4382
4383void DebuggerBackendDispatcher::setShouldBlackboxURL(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4384{
4385 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
4386 auto in_shouldBlackbox = m_backendDispatcher->getBoolean(protocol_parameters.get(), "shouldBlackbox"_s, true);
4387 auto in_opt_caseSensitive = m_backendDispatcher->getBoolean(protocol_parameters.get(), "caseSensitive"_s, false);
4388 auto in_opt_isRegex = m_backendDispatcher->getBoolean(protocol_parameters.get(), "isRegex"_s, false);
4389 if (m_backendDispatcher->hasProtocolErrors()) {
4390 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Debugger.setShouldBlackboxURL' can't be processed"_s);
4391 return;
4392 }
4393
4394#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4395 if (m_alternateDispatcher) {
4396 m_alternateDispatcher->setShouldBlackboxURL(protocol_requestId, in_url, *in_shouldBlackbox, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
4397 return;
4398 }
4399#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4400
4401 auto result = m_agent->setShouldBlackboxURL(in_url, *in_shouldBlackbox, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
4402 if (!result) {
4403 ASSERT(!result.error().isEmpty());
4404 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4405 return;
4406 }
4407
4408 auto protocol_jsonMessage = JSON::Object::create();
4409 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4410}
4411
4412Ref<HeapBackendDispatcher> HeapBackendDispatcher::create(BackendDispatcher& backendDispatcher, HeapBackendDispatcherHandler* agent)
4413{
4414 return adoptRef(*new HeapBackendDispatcher(backendDispatcher, agent));
4415}
4416
4417HeapBackendDispatcher::HeapBackendDispatcher(BackendDispatcher& backendDispatcher, HeapBackendDispatcherHandler* agent)
4418 : SupplementalBackendDispatcher(backendDispatcher)
4419 , m_agent(agent)
4420{
4421 m_backendDispatcher->registerDispatcherForDomain("Heap"_s, this);
4422}
4423
4424void HeapBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
4425{
4426 Ref<HeapBackendDispatcher> protect(*this);
4427
4428 auto protocol_parameters = protocol_message->getObject("params"_s);
4429
4430 using CallHandler = void (HeapBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
4431 using DispatchMap = HashMap<String, CallHandler>;
4432 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
4433 { "enable"_s, &HeapBackendDispatcher::enable },
4434 { "disable"_s, &HeapBackendDispatcher::disable },
4435 { "gc"_s, &HeapBackendDispatcher::gc },
4436 { "snapshot"_s, &HeapBackendDispatcher::snapshot },
4437 { "startTracking"_s, &HeapBackendDispatcher::startTracking },
4438 { "stopTracking"_s, &HeapBackendDispatcher::stopTracking },
4439 { "getPreview"_s, &HeapBackendDispatcher::getPreview },
4440 { "getRemoteObject"_s, &HeapBackendDispatcher::getRemoteObject },
4441 });
4442
4443 auto findResult = dispatchMap->find(protocol_method);
4444 if (findResult == dispatchMap->end()) {
4445 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Heap."_s, protocol_method, "' was not found"_s));
4446 return;
4447 }
4448
4449 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
4450}
4451
4452void HeapBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
4453{
4454#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4455 if (m_alternateDispatcher) {
4456 m_alternateDispatcher->enable(protocol_requestId);
4457 return;
4458 }
4459#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4460
4461 auto result = m_agent->enable();
4462 if (!result) {
4463 ASSERT(!result.error().isEmpty());
4464 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4465 return;
4466 }
4467
4468 auto protocol_jsonMessage = JSON::Object::create();
4469 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4470}
4471
4472void HeapBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
4473{
4474#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4475 if (m_alternateDispatcher) {
4476 m_alternateDispatcher->disable(protocol_requestId);
4477 return;
4478 }
4479#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4480
4481 auto result = m_agent->disable();
4482 if (!result) {
4483 ASSERT(!result.error().isEmpty());
4484 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4485 return;
4486 }
4487
4488 auto protocol_jsonMessage = JSON::Object::create();
4489 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4490}
4491
4492void HeapBackendDispatcher::gc(long protocol_requestId, RefPtr<JSON::Object>&&)
4493{
4494#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4495 if (m_alternateDispatcher) {
4496 m_alternateDispatcher->gc(protocol_requestId);
4497 return;
4498 }
4499#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4500
4501 auto result = m_agent->gc();
4502 if (!result) {
4503 ASSERT(!result.error().isEmpty());
4504 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4505 return;
4506 }
4507
4508 auto protocol_jsonMessage = JSON::Object::create();
4509 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4510}
4511
4512void HeapBackendDispatcher::snapshot(long protocol_requestId, RefPtr<JSON::Object>&&)
4513{
4514#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4515 if (m_alternateDispatcher) {
4516 m_alternateDispatcher->snapshot(protocol_requestId);
4517 return;
4518 }
4519#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4520
4521 auto result = m_agent->snapshot();
4522 if (!result) {
4523 ASSERT(!result.error().isEmpty());
4524 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4525 return;
4526 }
4527
4528 auto [out_timestamp, out_snapshotData] = WTFMove(result.value());
4529
4530 auto protocol_jsonMessage = JSON::Object::create();
4531 protocol_jsonMessage->setDouble("timestamp"_s, out_timestamp);
4532 protocol_jsonMessage->setString("snapshotData"_s, out_snapshotData);
4533 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4534}
4535
4536void HeapBackendDispatcher::startTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
4537{
4538#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4539 if (m_alternateDispatcher) {
4540 m_alternateDispatcher->startTracking(protocol_requestId);
4541 return;
4542 }
4543#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4544
4545 auto result = m_agent->startTracking();
4546 if (!result) {
4547 ASSERT(!result.error().isEmpty());
4548 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4549 return;
4550 }
4551
4552 auto protocol_jsonMessage = JSON::Object::create();
4553 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4554}
4555
4556void HeapBackendDispatcher::stopTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
4557{
4558#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4559 if (m_alternateDispatcher) {
4560 m_alternateDispatcher->stopTracking(protocol_requestId);
4561 return;
4562 }
4563#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4564
4565 auto result = m_agent->stopTracking();
4566 if (!result) {
4567 ASSERT(!result.error().isEmpty());
4568 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4569 return;
4570 }
4571
4572 auto protocol_jsonMessage = JSON::Object::create();
4573 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4574}
4575
4576void HeapBackendDispatcher::getPreview(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4577{
4578 auto in_heapObjectId = m_backendDispatcher->getInteger(protocol_parameters.get(), "heapObjectId"_s, true);
4579 if (m_backendDispatcher->hasProtocolErrors()) {
4580 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Heap.getPreview' can't be processed"_s);
4581 return;
4582 }
4583
4584#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4585 if (m_alternateDispatcher) {
4586 m_alternateDispatcher->getPreview(protocol_requestId, *in_heapObjectId);
4587 return;
4588 }
4589#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4590
4591 auto result = m_agent->getPreview(*in_heapObjectId);
4592 if (!result) {
4593 ASSERT(!result.error().isEmpty());
4594 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4595 return;
4596 }
4597
4598 auto [out_opt_string, out_opt_functionDetails, out_opt_preview] = WTFMove(result.value());
4599
4600 auto protocol_jsonMessage = JSON::Object::create();
4601 if (!!out_opt_string)
4602 protocol_jsonMessage->setString("string"_s, out_opt_string);
4603 if (!!out_opt_functionDetails)
4604 protocol_jsonMessage->setObject("functionDetails"_s, out_opt_functionDetails.releaseNonNull());
4605 if (!!out_opt_preview)
4606 protocol_jsonMessage->setObject("preview"_s, out_opt_preview.releaseNonNull());
4607 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4608}
4609
4610void HeapBackendDispatcher::getRemoteObject(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4611{
4612 auto in_heapObjectId = m_backendDispatcher->getInteger(protocol_parameters.get(), "heapObjectId"_s, true);
4613 auto in_opt_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, false);
4614 if (m_backendDispatcher->hasProtocolErrors()) {
4615 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Heap.getRemoteObject' can't be processed"_s);
4616 return;
4617 }
4618
4619#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4620 if (m_alternateDispatcher) {
4621 m_alternateDispatcher->getRemoteObject(protocol_requestId, *in_heapObjectId, in_opt_objectGroup);
4622 return;
4623 }
4624#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4625
4626 auto result = m_agent->getRemoteObject(*in_heapObjectId, in_opt_objectGroup);
4627 if (!result) {
4628 ASSERT(!result.error().isEmpty());
4629 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4630 return;
4631 }
4632
4633 auto out_result = WTFMove(result.value());
4634
4635 auto protocol_jsonMessage = JSON::Object::create();
4636 protocol_jsonMessage->setObject("result"_s, WTFMove(out_result));
4637 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4638}
4639
4640Ref<IndexedDBBackendDispatcher> IndexedDBBackendDispatcher::create(BackendDispatcher& backendDispatcher, IndexedDBBackendDispatcherHandler* agent)
4641{
4642 return adoptRef(*new IndexedDBBackendDispatcher(backendDispatcher, agent));
4643}
4644
4645IndexedDBBackendDispatcher::IndexedDBBackendDispatcher(BackendDispatcher& backendDispatcher, IndexedDBBackendDispatcherHandler* agent)
4646 : SupplementalBackendDispatcher(backendDispatcher)
4647 , m_agent(agent)
4648{
4649 m_backendDispatcher->registerDispatcherForDomain("IndexedDB"_s, this);
4650}
4651
4652void IndexedDBBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
4653{
4654 Ref<IndexedDBBackendDispatcher> protect(*this);
4655
4656 auto protocol_parameters = protocol_message->getObject("params"_s);
4657
4658 using CallHandler = void (IndexedDBBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
4659 using DispatchMap = HashMap<String, CallHandler>;
4660 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
4661 { "enable"_s, &IndexedDBBackendDispatcher::enable },
4662 { "disable"_s, &IndexedDBBackendDispatcher::disable },
4663 { "requestDatabaseNames"_s, &IndexedDBBackendDispatcher::requestDatabaseNames },
4664 { "requestDatabase"_s, &IndexedDBBackendDispatcher::requestDatabase },
4665 { "requestData"_s, &IndexedDBBackendDispatcher::requestData },
4666 { "clearObjectStore"_s, &IndexedDBBackendDispatcher::clearObjectStore },
4667 });
4668
4669 auto findResult = dispatchMap->find(protocol_method);
4670 if (findResult == dispatchMap->end()) {
4671 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'IndexedDB."_s, protocol_method, "' was not found"_s));
4672 return;
4673 }
4674
4675 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
4676}
4677
4678void IndexedDBBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
4679{
4680#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4681 if (m_alternateDispatcher) {
4682 m_alternateDispatcher->enable(protocol_requestId);
4683 return;
4684 }
4685#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4686
4687 auto result = m_agent->enable();
4688 if (!result) {
4689 ASSERT(!result.error().isEmpty());
4690 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4691 return;
4692 }
4693
4694 auto protocol_jsonMessage = JSON::Object::create();
4695 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4696}
4697
4698void IndexedDBBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
4699{
4700#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4701 if (m_alternateDispatcher) {
4702 m_alternateDispatcher->disable(protocol_requestId);
4703 return;
4704 }
4705#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4706
4707 auto result = m_agent->disable();
4708 if (!result) {
4709 ASSERT(!result.error().isEmpty());
4710 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4711 return;
4712 }
4713
4714 auto protocol_jsonMessage = JSON::Object::create();
4715 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4716}
4717
4718IndexedDBBackendDispatcherHandler::RequestDatabaseNamesCallback::RequestDatabaseNamesCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { }
4719
4720void IndexedDBBackendDispatcherHandler::RequestDatabaseNamesCallback::sendSuccess(Ref<JSON::ArrayOf<String>>&& databaseNames)
4721{
4722 auto protocol_jsonMessage = JSON::Object::create();
4723 protocol_jsonMessage->setArray("databaseNames"_s, WTFMove(databaseNames));
4724 CallbackBase::sendSuccess(WTFMove(protocol_jsonMessage));
4725}
4726
4727void IndexedDBBackendDispatcher::requestDatabaseNames(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4728{
4729 auto in_securityOrigin = m_backendDispatcher->getString(protocol_parameters.get(), "securityOrigin"_s, true);
4730 if (m_backendDispatcher->hasProtocolErrors()) {
4731 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'IndexedDB.requestDatabaseNames' can't be processed"_s);
4732 return;
4733 }
4734
4735#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4736 if (m_alternateDispatcher) {
4737 m_alternateDispatcher->requestDatabaseNames(protocol_requestId, in_securityOrigin);
4738 return;
4739 }
4740#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4741
4742 m_agent->requestDatabaseNames(in_securityOrigin, adoptRef(*new IndexedDBBackendDispatcherHandler::RequestDatabaseNamesCallback(m_backendDispatcher.copyRef(), protocol_requestId)));
4743}
4744
4745IndexedDBBackendDispatcherHandler::RequestDatabaseCallback::RequestDatabaseCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { }
4746
4747void IndexedDBBackendDispatcherHandler::RequestDatabaseCallback::sendSuccess(Ref<Protocol::IndexedDB::DatabaseWithObjectStores>&& databaseWithObjectStores)
4748{
4749 auto protocol_jsonMessage = JSON::Object::create();
4750 protocol_jsonMessage->setObject("databaseWithObjectStores"_s, WTFMove(databaseWithObjectStores));
4751 CallbackBase::sendSuccess(WTFMove(protocol_jsonMessage));
4752}
4753
4754void IndexedDBBackendDispatcher::requestDatabase(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4755{
4756 auto in_securityOrigin = m_backendDispatcher->getString(protocol_parameters.get(), "securityOrigin"_s, true);
4757 auto in_databaseName = m_backendDispatcher->getString(protocol_parameters.get(), "databaseName"_s, true);
4758 if (m_backendDispatcher->hasProtocolErrors()) {
4759 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'IndexedDB.requestDatabase' can't be processed"_s);
4760 return;
4761 }
4762
4763#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4764 if (m_alternateDispatcher) {
4765 m_alternateDispatcher->requestDatabase(protocol_requestId, in_securityOrigin, in_databaseName);
4766 return;
4767 }
4768#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4769
4770 m_agent->requestDatabase(in_securityOrigin, in_databaseName, adoptRef(*new IndexedDBBackendDispatcherHandler::RequestDatabaseCallback(m_backendDispatcher.copyRef(), protocol_requestId)));
4771}
4772
4773IndexedDBBackendDispatcherHandler::RequestDataCallback::RequestDataCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { }
4774
4775void IndexedDBBackendDispatcherHandler::RequestDataCallback::sendSuccess(Ref<JSON::ArrayOf<Protocol::IndexedDB::DataEntry>>&& objectStoreDataEntries, bool hasMore)
4776{
4777 auto protocol_jsonMessage = JSON::Object::create();
4778 protocol_jsonMessage->setArray("objectStoreDataEntries"_s, WTFMove(objectStoreDataEntries));
4779 protocol_jsonMessage->setBoolean("hasMore"_s, hasMore);
4780 CallbackBase::sendSuccess(WTFMove(protocol_jsonMessage));
4781}
4782
4783void IndexedDBBackendDispatcher::requestData(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4784{
4785 auto in_securityOrigin = m_backendDispatcher->getString(protocol_parameters.get(), "securityOrigin"_s, true);
4786 auto in_databaseName = m_backendDispatcher->getString(protocol_parameters.get(), "databaseName"_s, true);
4787 auto in_objectStoreName = m_backendDispatcher->getString(protocol_parameters.get(), "objectStoreName"_s, true);
4788 auto in_indexName = m_backendDispatcher->getString(protocol_parameters.get(), "indexName"_s, true);
4789 auto in_skipCount = m_backendDispatcher->getInteger(protocol_parameters.get(), "skipCount"_s, true);
4790 auto in_pageSize = m_backendDispatcher->getInteger(protocol_parameters.get(), "pageSize"_s, true);
4791 auto in_opt_keyRange = m_backendDispatcher->getObject(protocol_parameters.get(), "keyRange"_s, false);
4792 if (m_backendDispatcher->hasProtocolErrors()) {
4793 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'IndexedDB.requestData' can't be processed"_s);
4794 return;
4795 }
4796
4797#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4798 if (m_alternateDispatcher) {
4799 m_alternateDispatcher->requestData(protocol_requestId, in_securityOrigin, in_databaseName, in_objectStoreName, in_indexName, *in_skipCount, *in_pageSize, WTFMove(in_opt_keyRange));
4800 return;
4801 }
4802#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4803
4804 m_agent->requestData(in_securityOrigin, in_databaseName, in_objectStoreName, in_indexName, *in_skipCount, *in_pageSize, WTFMove(in_opt_keyRange), adoptRef(*new IndexedDBBackendDispatcherHandler::RequestDataCallback(m_backendDispatcher.copyRef(), protocol_requestId)));
4805}
4806
4807IndexedDBBackendDispatcherHandler::ClearObjectStoreCallback::ClearObjectStoreCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { }
4808
4809void IndexedDBBackendDispatcherHandler::ClearObjectStoreCallback::sendSuccess()
4810{
4811 auto protocol_jsonMessage = JSON::Object::create();
4812
4813 CallbackBase::sendSuccess(WTFMove(protocol_jsonMessage));
4814}
4815
4816void IndexedDBBackendDispatcher::clearObjectStore(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
4817{
4818 auto in_securityOrigin = m_backendDispatcher->getString(protocol_parameters.get(), "securityOrigin"_s, true);
4819 auto in_databaseName = m_backendDispatcher->getString(protocol_parameters.get(), "databaseName"_s, true);
4820 auto in_objectStoreName = m_backendDispatcher->getString(protocol_parameters.get(), "objectStoreName"_s, true);
4821 if (m_backendDispatcher->hasProtocolErrors()) {
4822 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'IndexedDB.clearObjectStore' can't be processed"_s);
4823 return;
4824 }
4825
4826#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4827 if (m_alternateDispatcher) {
4828 m_alternateDispatcher->clearObjectStore(protocol_requestId, in_securityOrigin, in_databaseName, in_objectStoreName);
4829 return;
4830 }
4831#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4832
4833 m_agent->clearObjectStore(in_securityOrigin, in_databaseName, in_objectStoreName, adoptRef(*new IndexedDBBackendDispatcherHandler::ClearObjectStoreCallback(m_backendDispatcher.copyRef(), protocol_requestId)));
4834}
4835
4836Ref<InspectorBackendDispatcher> InspectorBackendDispatcher::create(BackendDispatcher& backendDispatcher, InspectorBackendDispatcherHandler* agent)
4837{
4838 return adoptRef(*new InspectorBackendDispatcher(backendDispatcher, agent));
4839}
4840
4841InspectorBackendDispatcher::InspectorBackendDispatcher(BackendDispatcher& backendDispatcher, InspectorBackendDispatcherHandler* agent)
4842 : SupplementalBackendDispatcher(backendDispatcher)
4843 , m_agent(agent)
4844{
4845 m_backendDispatcher->registerDispatcherForDomain("Inspector"_s, this);
4846}
4847
4848void InspectorBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
4849{
4850 Ref<InspectorBackendDispatcher> protect(*this);
4851
4852 auto protocol_parameters = protocol_message->getObject("params"_s);
4853
4854 if (protocol_method == "enable"_s) {
4855 enable(protocol_requestId, WTFMove(protocol_parameters));
4856 return;
4857 }
4858 if (protocol_method == "disable"_s) {
4859 disable(protocol_requestId, WTFMove(protocol_parameters));
4860 return;
4861 }
4862 if (protocol_method == "initialized"_s) {
4863 initialized(protocol_requestId, WTFMove(protocol_parameters));
4864 return;
4865 }
4866
4867 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Inspector."_s, protocol_method, "' was not found"_s));
4868}
4869
4870void InspectorBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
4871{
4872#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4873 if (m_alternateDispatcher) {
4874 m_alternateDispatcher->enable(protocol_requestId);
4875 return;
4876 }
4877#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4878
4879 auto result = m_agent->enable();
4880 if (!result) {
4881 ASSERT(!result.error().isEmpty());
4882 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4883 return;
4884 }
4885
4886 auto protocol_jsonMessage = JSON::Object::create();
4887 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4888}
4889
4890void InspectorBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
4891{
4892#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4893 if (m_alternateDispatcher) {
4894 m_alternateDispatcher->disable(protocol_requestId);
4895 return;
4896 }
4897#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4898
4899 auto result = m_agent->disable();
4900 if (!result) {
4901 ASSERT(!result.error().isEmpty());
4902 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4903 return;
4904 }
4905
4906 auto protocol_jsonMessage = JSON::Object::create();
4907 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4908}
4909
4910void InspectorBackendDispatcher::initialized(long protocol_requestId, RefPtr<JSON::Object>&&)
4911{
4912#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4913 if (m_alternateDispatcher) {
4914 m_alternateDispatcher->initialized(protocol_requestId);
4915 return;
4916 }
4917#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4918
4919 auto result = m_agent->initialized();
4920 if (!result) {
4921 ASSERT(!result.error().isEmpty());
4922 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4923 return;
4924 }
4925
4926 auto protocol_jsonMessage = JSON::Object::create();
4927 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4928}
4929
4930Ref<LayerTreeBackendDispatcher> LayerTreeBackendDispatcher::create(BackendDispatcher& backendDispatcher, LayerTreeBackendDispatcherHandler* agent)
4931{
4932 return adoptRef(*new LayerTreeBackendDispatcher(backendDispatcher, agent));
4933}
4934
4935LayerTreeBackendDispatcher::LayerTreeBackendDispatcher(BackendDispatcher& backendDispatcher, LayerTreeBackendDispatcherHandler* agent)
4936 : SupplementalBackendDispatcher(backendDispatcher)
4937 , m_agent(agent)
4938{
4939 m_backendDispatcher->registerDispatcherForDomain("LayerTree"_s, this);
4940}
4941
4942void LayerTreeBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
4943{
4944 Ref<LayerTreeBackendDispatcher> protect(*this);
4945
4946 auto protocol_parameters = protocol_message->getObject("params"_s);
4947
4948 if (protocol_method == "enable"_s) {
4949 enable(protocol_requestId, WTFMove(protocol_parameters));
4950 return;
4951 }
4952 if (protocol_method == "disable"_s) {
4953 disable(protocol_requestId, WTFMove(protocol_parameters));
4954 return;
4955 }
4956 if (protocol_method == "layersForNode"_s) {
4957 layersForNode(protocol_requestId, WTFMove(protocol_parameters));
4958 return;
4959 }
4960 if (protocol_method == "reasonsForCompositingLayer"_s) {
4961 reasonsForCompositingLayer(protocol_requestId, WTFMove(protocol_parameters));
4962 return;
4963 }
4964
4965 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'LayerTree."_s, protocol_method, "' was not found"_s));
4966}
4967
4968void LayerTreeBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
4969{
4970#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4971 if (m_alternateDispatcher) {
4972 m_alternateDispatcher->enable(protocol_requestId);
4973 return;
4974 }
4975#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4976
4977 auto result = m_agent->enable();
4978 if (!result) {
4979 ASSERT(!result.error().isEmpty());
4980 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
4981 return;
4982 }
4983
4984 auto protocol_jsonMessage = JSON::Object::create();
4985 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
4986}
4987
4988void LayerTreeBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
4989{
4990#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4991 if (m_alternateDispatcher) {
4992 m_alternateDispatcher->disable(protocol_requestId);
4993 return;
4994 }
4995#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
4996
4997 auto result = m_agent->disable();
4998 if (!result) {
4999 ASSERT(!result.error().isEmpty());
5000 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5001 return;
5002 }
5003
5004 auto protocol_jsonMessage = JSON::Object::create();
5005 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5006}
5007
5008void LayerTreeBackendDispatcher::layersForNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5009{
5010 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
5011 if (m_backendDispatcher->hasProtocolErrors()) {
5012 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'LayerTree.layersForNode' can't be processed"_s);
5013 return;
5014 }
5015
5016#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5017 if (m_alternateDispatcher) {
5018 m_alternateDispatcher->layersForNode(protocol_requestId, *in_nodeId);
5019 return;
5020 }
5021#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5022
5023 auto result = m_agent->layersForNode(*in_nodeId);
5024 if (!result) {
5025 ASSERT(!result.error().isEmpty());
5026 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5027 return;
5028 }
5029
5030 auto out_layers = WTFMove(result.value());
5031
5032 auto protocol_jsonMessage = JSON::Object::create();
5033 protocol_jsonMessage->setArray("layers"_s, WTFMove(out_layers));
5034 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5035}
5036
5037void LayerTreeBackendDispatcher::reasonsForCompositingLayer(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5038{
5039 auto in_layerId = m_backendDispatcher->getString(protocol_parameters.get(), "layerId"_s, true);
5040 if (m_backendDispatcher->hasProtocolErrors()) {
5041 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'LayerTree.reasonsForCompositingLayer' can't be processed"_s);
5042 return;
5043 }
5044
5045#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5046 if (m_alternateDispatcher) {
5047 m_alternateDispatcher->reasonsForCompositingLayer(protocol_requestId, in_layerId);
5048 return;
5049 }
5050#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5051
5052 auto result = m_agent->reasonsForCompositingLayer(in_layerId);
5053 if (!result) {
5054 ASSERT(!result.error().isEmpty());
5055 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5056 return;
5057 }
5058
5059 auto out_compositingReasons = WTFMove(result.value());
5060
5061 auto protocol_jsonMessage = JSON::Object::create();
5062 protocol_jsonMessage->setObject("compositingReasons"_s, WTFMove(out_compositingReasons));
5063 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5064}
5065
5066#if defined(ENABLE_RESOURCE_USAGE) && ENABLE_RESOURCE_USAGE
5067Ref<MemoryBackendDispatcher> MemoryBackendDispatcher::create(BackendDispatcher& backendDispatcher, MemoryBackendDispatcherHandler* agent)
5068{
5069 return adoptRef(*new MemoryBackendDispatcher(backendDispatcher, agent));
5070}
5071
5072MemoryBackendDispatcher::MemoryBackendDispatcher(BackendDispatcher& backendDispatcher, MemoryBackendDispatcherHandler* agent)
5073 : SupplementalBackendDispatcher(backendDispatcher)
5074 , m_agent(agent)
5075{
5076 m_backendDispatcher->registerDispatcherForDomain("Memory"_s, this);
5077}
5078
5079void MemoryBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
5080{
5081 Ref<MemoryBackendDispatcher> protect(*this);
5082
5083 auto protocol_parameters = protocol_message->getObject("params"_s);
5084
5085 if (protocol_method == "enable"_s) {
5086 enable(protocol_requestId, WTFMove(protocol_parameters));
5087 return;
5088 }
5089 if (protocol_method == "disable"_s) {
5090 disable(protocol_requestId, WTFMove(protocol_parameters));
5091 return;
5092 }
5093 if (protocol_method == "startTracking"_s) {
5094 startTracking(protocol_requestId, WTFMove(protocol_parameters));
5095 return;
5096 }
5097 if (protocol_method == "stopTracking"_s) {
5098 stopTracking(protocol_requestId, WTFMove(protocol_parameters));
5099 return;
5100 }
5101
5102 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Memory."_s, protocol_method, "' was not found"_s));
5103}
5104
5105void MemoryBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
5106{
5107#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5108 if (m_alternateDispatcher) {
5109 m_alternateDispatcher->enable(protocol_requestId);
5110 return;
5111 }
5112#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5113
5114 auto result = m_agent->enable();
5115 if (!result) {
5116 ASSERT(!result.error().isEmpty());
5117 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5118 return;
5119 }
5120
5121 auto protocol_jsonMessage = JSON::Object::create();
5122 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5123}
5124
5125void MemoryBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
5126{
5127#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5128 if (m_alternateDispatcher) {
5129 m_alternateDispatcher->disable(protocol_requestId);
5130 return;
5131 }
5132#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5133
5134 auto result = m_agent->disable();
5135 if (!result) {
5136 ASSERT(!result.error().isEmpty());
5137 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5138 return;
5139 }
5140
5141 auto protocol_jsonMessage = JSON::Object::create();
5142 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5143}
5144
5145void MemoryBackendDispatcher::startTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
5146{
5147#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5148 if (m_alternateDispatcher) {
5149 m_alternateDispatcher->startTracking(protocol_requestId);
5150 return;
5151 }
5152#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5153
5154 auto result = m_agent->startTracking();
5155 if (!result) {
5156 ASSERT(!result.error().isEmpty());
5157 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5158 return;
5159 }
5160
5161 auto protocol_jsonMessage = JSON::Object::create();
5162 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5163}
5164
5165void MemoryBackendDispatcher::stopTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
5166{
5167#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5168 if (m_alternateDispatcher) {
5169 m_alternateDispatcher->stopTracking(protocol_requestId);
5170 return;
5171 }
5172#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5173
5174 auto result = m_agent->stopTracking();
5175 if (!result) {
5176 ASSERT(!result.error().isEmpty());
5177 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5178 return;
5179 }
5180
5181 auto protocol_jsonMessage = JSON::Object::create();
5182 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5183}
5184#endif // defined(ENABLE_RESOURCE_USAGE) && ENABLE_RESOURCE_USAGE
5185
5186Ref<NetworkBackendDispatcher> NetworkBackendDispatcher::create(BackendDispatcher& backendDispatcher, NetworkBackendDispatcherHandler* agent)
5187{
5188 return adoptRef(*new NetworkBackendDispatcher(backendDispatcher, agent));
5189}
5190
5191NetworkBackendDispatcher::NetworkBackendDispatcher(BackendDispatcher& backendDispatcher, NetworkBackendDispatcherHandler* agent)
5192 : SupplementalBackendDispatcher(backendDispatcher)
5193 , m_agent(agent)
5194{
5195 m_backendDispatcher->registerDispatcherForDomain("Network"_s, this);
5196}
5197
5198void NetworkBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
5199{
5200 Ref<NetworkBackendDispatcher> protect(*this);
5201
5202 auto protocol_parameters = protocol_message->getObject("params"_s);
5203
5204 using CallHandler = void (NetworkBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
5205 using DispatchMap = HashMap<String, CallHandler>;
5206 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
5207 { "enable"_s, &NetworkBackendDispatcher::enable },
5208 { "disable"_s, &NetworkBackendDispatcher::disable },
5209 { "setExtraHTTPHeaders"_s, &NetworkBackendDispatcher::setExtraHTTPHeaders },
5210 { "getResponseBody"_s, &NetworkBackendDispatcher::getResponseBody },
5211 { "setResourceCachingDisabled"_s, &NetworkBackendDispatcher::setResourceCachingDisabled },
5212 { "loadResource"_s, &NetworkBackendDispatcher::loadResource },
5213 { "getSerializedCertificate"_s, &NetworkBackendDispatcher::getSerializedCertificate },
5214 { "resolveWebSocket"_s, &NetworkBackendDispatcher::resolveWebSocket },
5215 { "setInterceptionEnabled"_s, &NetworkBackendDispatcher::setInterceptionEnabled },
5216 { "addInterception"_s, &NetworkBackendDispatcher::addInterception },
5217 { "removeInterception"_s, &NetworkBackendDispatcher::removeInterception },
5218 { "interceptContinue"_s, &NetworkBackendDispatcher::interceptContinue },
5219 { "interceptWithRequest"_s, &NetworkBackendDispatcher::interceptWithRequest },
5220 { "interceptWithResponse"_s, &NetworkBackendDispatcher::interceptWithResponse },
5221 { "interceptRequestWithResponse"_s, &NetworkBackendDispatcher::interceptRequestWithResponse },
5222 { "interceptRequestWithError"_s, &NetworkBackendDispatcher::interceptRequestWithError },
5223 });
5224
5225 auto findResult = dispatchMap->find(protocol_method);
5226 if (findResult == dispatchMap->end()) {
5227 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Network."_s, protocol_method, "' was not found"_s));
5228 return;
5229 }
5230
5231 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
5232}
5233
5234void NetworkBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
5235{
5236#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5237 if (m_alternateDispatcher) {
5238 m_alternateDispatcher->enable(protocol_requestId);
5239 return;
5240 }
5241#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5242
5243 auto result = m_agent->enable();
5244 if (!result) {
5245 ASSERT(!result.error().isEmpty());
5246 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5247 return;
5248 }
5249
5250 auto protocol_jsonMessage = JSON::Object::create();
5251 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5252}
5253
5254void NetworkBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
5255{
5256#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5257 if (m_alternateDispatcher) {
5258 m_alternateDispatcher->disable(protocol_requestId);
5259 return;
5260 }
5261#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5262
5263 auto result = m_agent->disable();
5264 if (!result) {
5265 ASSERT(!result.error().isEmpty());
5266 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5267 return;
5268 }
5269
5270 auto protocol_jsonMessage = JSON::Object::create();
5271 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5272}
5273
5274void NetworkBackendDispatcher::setExtraHTTPHeaders(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5275{
5276 auto in_headers = m_backendDispatcher->getObject(protocol_parameters.get(), "headers"_s, true);
5277 if (m_backendDispatcher->hasProtocolErrors()) {
5278 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.setExtraHTTPHeaders' can't be processed"_s);
5279 return;
5280 }
5281
5282#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5283 if (m_alternateDispatcher) {
5284 m_alternateDispatcher->setExtraHTTPHeaders(protocol_requestId, in_headers.releaseNonNull());
5285 return;
5286 }
5287#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5288
5289 auto result = m_agent->setExtraHTTPHeaders(in_headers.releaseNonNull());
5290 if (!result) {
5291 ASSERT(!result.error().isEmpty());
5292 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5293 return;
5294 }
5295
5296 auto protocol_jsonMessage = JSON::Object::create();
5297 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5298}
5299
5300void NetworkBackendDispatcher::getResponseBody(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5301{
5302 auto in_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, true);
5303 if (m_backendDispatcher->hasProtocolErrors()) {
5304 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.getResponseBody' can't be processed"_s);
5305 return;
5306 }
5307
5308#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5309 if (m_alternateDispatcher) {
5310 m_alternateDispatcher->getResponseBody(protocol_requestId, in_requestId);
5311 return;
5312 }
5313#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5314
5315 auto result = m_agent->getResponseBody(in_requestId);
5316 if (!result) {
5317 ASSERT(!result.error().isEmpty());
5318 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5319 return;
5320 }
5321
5322 auto [out_body, out_base64Encoded] = WTFMove(result.value());
5323
5324 auto protocol_jsonMessage = JSON::Object::create();
5325 protocol_jsonMessage->setString("body"_s, out_body);
5326 protocol_jsonMessage->setBoolean("base64Encoded"_s, out_base64Encoded);
5327 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5328}
5329
5330void NetworkBackendDispatcher::setResourceCachingDisabled(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5331{
5332 auto in_disabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "disabled"_s, true);
5333 if (m_backendDispatcher->hasProtocolErrors()) {
5334 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.setResourceCachingDisabled' can't be processed"_s);
5335 return;
5336 }
5337
5338#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5339 if (m_alternateDispatcher) {
5340 m_alternateDispatcher->setResourceCachingDisabled(protocol_requestId, *in_disabled);
5341 return;
5342 }
5343#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5344
5345 auto result = m_agent->setResourceCachingDisabled(*in_disabled);
5346 if (!result) {
5347 ASSERT(!result.error().isEmpty());
5348 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5349 return;
5350 }
5351
5352 auto protocol_jsonMessage = JSON::Object::create();
5353 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5354}
5355
5356NetworkBackendDispatcherHandler::LoadResourceCallback::LoadResourceCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { }
5357
5358void NetworkBackendDispatcherHandler::LoadResourceCallback::sendSuccess(const String& content, const String& mimeType, int status)
5359{
5360 auto protocol_jsonMessage = JSON::Object::create();
5361 protocol_jsonMessage->setString("content"_s, content);
5362 protocol_jsonMessage->setString("mimeType"_s, mimeType);
5363 protocol_jsonMessage->setInteger("status"_s, status);
5364 CallbackBase::sendSuccess(WTFMove(protocol_jsonMessage));
5365}
5366
5367void NetworkBackendDispatcher::loadResource(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5368{
5369 auto in_frameId = m_backendDispatcher->getString(protocol_parameters.get(), "frameId"_s, true);
5370 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
5371 if (m_backendDispatcher->hasProtocolErrors()) {
5372 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.loadResource' can't be processed"_s);
5373 return;
5374 }
5375
5376#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5377 if (m_alternateDispatcher) {
5378 m_alternateDispatcher->loadResource(protocol_requestId, in_frameId, in_url);
5379 return;
5380 }
5381#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5382
5383 m_agent->loadResource(in_frameId, in_url, adoptRef(*new NetworkBackendDispatcherHandler::LoadResourceCallback(m_backendDispatcher.copyRef(), protocol_requestId)));
5384}
5385
5386void NetworkBackendDispatcher::getSerializedCertificate(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5387{
5388 auto in_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, true);
5389 if (m_backendDispatcher->hasProtocolErrors()) {
5390 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.getSerializedCertificate' can't be processed"_s);
5391 return;
5392 }
5393
5394#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5395 if (m_alternateDispatcher) {
5396 m_alternateDispatcher->getSerializedCertificate(protocol_requestId, in_requestId);
5397 return;
5398 }
5399#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5400
5401 auto result = m_agent->getSerializedCertificate(in_requestId);
5402 if (!result) {
5403 ASSERT(!result.error().isEmpty());
5404 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5405 return;
5406 }
5407
5408 auto out_serializedCertificate = WTFMove(result.value());
5409
5410 auto protocol_jsonMessage = JSON::Object::create();
5411 protocol_jsonMessage->setString("serializedCertificate"_s, out_serializedCertificate);
5412 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5413}
5414
5415void NetworkBackendDispatcher::resolveWebSocket(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5416{
5417 auto in_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, true);
5418 auto in_opt_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, false);
5419 if (m_backendDispatcher->hasProtocolErrors()) {
5420 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.resolveWebSocket' can't be processed"_s);
5421 return;
5422 }
5423
5424#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5425 if (m_alternateDispatcher) {
5426 m_alternateDispatcher->resolveWebSocket(protocol_requestId, in_requestId, in_opt_objectGroup);
5427 return;
5428 }
5429#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5430
5431 auto result = m_agent->resolveWebSocket(in_requestId, in_opt_objectGroup);
5432 if (!result) {
5433 ASSERT(!result.error().isEmpty());
5434 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5435 return;
5436 }
5437
5438 auto out_object = WTFMove(result.value());
5439
5440 auto protocol_jsonMessage = JSON::Object::create();
5441 protocol_jsonMessage->setObject("object"_s, WTFMove(out_object));
5442 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5443}
5444
5445void NetworkBackendDispatcher::setInterceptionEnabled(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5446{
5447 auto in_enabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "enabled"_s, true);
5448 if (m_backendDispatcher->hasProtocolErrors()) {
5449 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.setInterceptionEnabled' can't be processed"_s);
5450 return;
5451 }
5452
5453#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5454 if (m_alternateDispatcher) {
5455 m_alternateDispatcher->setInterceptionEnabled(protocol_requestId, *in_enabled);
5456 return;
5457 }
5458#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5459
5460 auto result = m_agent->setInterceptionEnabled(*in_enabled);
5461 if (!result) {
5462 ASSERT(!result.error().isEmpty());
5463 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5464 return;
5465 }
5466
5467 auto protocol_jsonMessage = JSON::Object::create();
5468 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5469}
5470
5471void NetworkBackendDispatcher::addInterception(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5472{
5473 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
5474 auto in_stage_json = m_backendDispatcher->getString(protocol_parameters.get(), "stage"_s, true);
5475 auto in_opt_caseSensitive = m_backendDispatcher->getBoolean(protocol_parameters.get(), "caseSensitive"_s, false);
5476 auto in_opt_isRegex = m_backendDispatcher->getBoolean(protocol_parameters.get(), "isRegex"_s, false);
5477 if (m_backendDispatcher->hasProtocolErrors()) {
5478 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.addInterception' can't be processed"_s);
5479 return;
5480 }
5481
5482#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5483 if (m_alternateDispatcher) {
5484 m_alternateDispatcher->addInterception(protocol_requestId, in_url, in_stage_json, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
5485 return;
5486 }
5487#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5488
5489 auto in_stage = Protocol::Helpers::parseEnumValueFromString<Protocol::Network::NetworkStage>(in_stage_json);
5490 if (!in_stage) {
5491 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown stage: "_s, in_stage_json));
5492 return;
5493 }
5494
5495 auto result = m_agent->addInterception(in_url, *in_stage, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
5496 if (!result) {
5497 ASSERT(!result.error().isEmpty());
5498 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5499 return;
5500 }
5501
5502 auto protocol_jsonMessage = JSON::Object::create();
5503 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5504}
5505
5506void NetworkBackendDispatcher::removeInterception(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5507{
5508 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
5509 auto in_stage_json = m_backendDispatcher->getString(protocol_parameters.get(), "stage"_s, true);
5510 auto in_opt_caseSensitive = m_backendDispatcher->getBoolean(protocol_parameters.get(), "caseSensitive"_s, false);
5511 auto in_opt_isRegex = m_backendDispatcher->getBoolean(protocol_parameters.get(), "isRegex"_s, false);
5512 if (m_backendDispatcher->hasProtocolErrors()) {
5513 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.removeInterception' can't be processed"_s);
5514 return;
5515 }
5516
5517#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5518 if (m_alternateDispatcher) {
5519 m_alternateDispatcher->removeInterception(protocol_requestId, in_url, in_stage_json, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
5520 return;
5521 }
5522#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5523
5524 auto in_stage = Protocol::Helpers::parseEnumValueFromString<Protocol::Network::NetworkStage>(in_stage_json);
5525 if (!in_stage) {
5526 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown stage: "_s, in_stage_json));
5527 return;
5528 }
5529
5530 auto result = m_agent->removeInterception(in_url, *in_stage, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
5531 if (!result) {
5532 ASSERT(!result.error().isEmpty());
5533 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5534 return;
5535 }
5536
5537 auto protocol_jsonMessage = JSON::Object::create();
5538 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5539}
5540
5541void NetworkBackendDispatcher::interceptContinue(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5542{
5543 auto in_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, true);
5544 auto in_stage_json = m_backendDispatcher->getString(protocol_parameters.get(), "stage"_s, true);
5545 if (m_backendDispatcher->hasProtocolErrors()) {
5546 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.interceptContinue' can't be processed"_s);
5547 return;
5548 }
5549
5550#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5551 if (m_alternateDispatcher) {
5552 m_alternateDispatcher->interceptContinue(protocol_requestId, in_requestId, in_stage_json);
5553 return;
5554 }
5555#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5556
5557 auto in_stage = Protocol::Helpers::parseEnumValueFromString<Protocol::Network::NetworkStage>(in_stage_json);
5558 if (!in_stage) {
5559 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown stage: "_s, in_stage_json));
5560 return;
5561 }
5562
5563 auto result = m_agent->interceptContinue(in_requestId, *in_stage);
5564 if (!result) {
5565 ASSERT(!result.error().isEmpty());
5566 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5567 return;
5568 }
5569
5570 auto protocol_jsonMessage = JSON::Object::create();
5571 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5572}
5573
5574void NetworkBackendDispatcher::interceptWithRequest(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5575{
5576 auto in_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, true);
5577 auto in_opt_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, false);
5578 auto in_opt_method = m_backendDispatcher->getString(protocol_parameters.get(), "method"_s, false);
5579 auto in_opt_headers = m_backendDispatcher->getObject(protocol_parameters.get(), "headers"_s, false);
5580 auto in_opt_postData = m_backendDispatcher->getString(protocol_parameters.get(), "postData"_s, false);
5581 if (m_backendDispatcher->hasProtocolErrors()) {
5582 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.interceptWithRequest' can't be processed"_s);
5583 return;
5584 }
5585
5586#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5587 if (m_alternateDispatcher) {
5588 m_alternateDispatcher->interceptWithRequest(protocol_requestId, in_requestId, in_opt_url, in_opt_method, WTFMove(in_opt_headers), in_opt_postData);
5589 return;
5590 }
5591#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5592
5593 auto result = m_agent->interceptWithRequest(in_requestId, in_opt_url, in_opt_method, WTFMove(in_opt_headers), in_opt_postData);
5594 if (!result) {
5595 ASSERT(!result.error().isEmpty());
5596 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5597 return;
5598 }
5599
5600 auto protocol_jsonMessage = JSON::Object::create();
5601 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5602}
5603
5604void NetworkBackendDispatcher::interceptWithResponse(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5605{
5606 auto in_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, true);
5607 auto in_content = m_backendDispatcher->getString(protocol_parameters.get(), "content"_s, true);
5608 auto in_base64Encoded = m_backendDispatcher->getBoolean(protocol_parameters.get(), "base64Encoded"_s, true);
5609 auto in_opt_mimeType = m_backendDispatcher->getString(protocol_parameters.get(), "mimeType"_s, false);
5610 auto in_opt_status = m_backendDispatcher->getInteger(protocol_parameters.get(), "status"_s, false);
5611 auto in_opt_statusText = m_backendDispatcher->getString(protocol_parameters.get(), "statusText"_s, false);
5612 auto in_opt_headers = m_backendDispatcher->getObject(protocol_parameters.get(), "headers"_s, false);
5613 if (m_backendDispatcher->hasProtocolErrors()) {
5614 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.interceptWithResponse' can't be processed"_s);
5615 return;
5616 }
5617
5618#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5619 if (m_alternateDispatcher) {
5620 m_alternateDispatcher->interceptWithResponse(protocol_requestId, in_requestId, in_content, *in_base64Encoded, in_opt_mimeType, WTFMove(in_opt_status), in_opt_statusText, WTFMove(in_opt_headers));
5621 return;
5622 }
5623#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5624
5625 auto result = m_agent->interceptWithResponse(in_requestId, in_content, *in_base64Encoded, in_opt_mimeType, WTFMove(in_opt_status), in_opt_statusText, WTFMove(in_opt_headers));
5626 if (!result) {
5627 ASSERT(!result.error().isEmpty());
5628 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5629 return;
5630 }
5631
5632 auto protocol_jsonMessage = JSON::Object::create();
5633 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5634}
5635
5636void NetworkBackendDispatcher::interceptRequestWithResponse(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5637{
5638 auto in_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, true);
5639 auto in_content = m_backendDispatcher->getString(protocol_parameters.get(), "content"_s, true);
5640 auto in_base64Encoded = m_backendDispatcher->getBoolean(protocol_parameters.get(), "base64Encoded"_s, true);
5641 auto in_mimeType = m_backendDispatcher->getString(protocol_parameters.get(), "mimeType"_s, true);
5642 auto in_status = m_backendDispatcher->getInteger(protocol_parameters.get(), "status"_s, true);
5643 auto in_statusText = m_backendDispatcher->getString(protocol_parameters.get(), "statusText"_s, true);
5644 auto in_headers = m_backendDispatcher->getObject(protocol_parameters.get(), "headers"_s, true);
5645 if (m_backendDispatcher->hasProtocolErrors()) {
5646 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.interceptRequestWithResponse' can't be processed"_s);
5647 return;
5648 }
5649
5650#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5651 if (m_alternateDispatcher) {
5652 m_alternateDispatcher->interceptRequestWithResponse(protocol_requestId, in_requestId, in_content, *in_base64Encoded, in_mimeType, *in_status, in_statusText, in_headers.releaseNonNull());
5653 return;
5654 }
5655#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5656
5657 auto result = m_agent->interceptRequestWithResponse(in_requestId, in_content, *in_base64Encoded, in_mimeType, *in_status, in_statusText, in_headers.releaseNonNull());
5658 if (!result) {
5659 ASSERT(!result.error().isEmpty());
5660 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5661 return;
5662 }
5663
5664 auto protocol_jsonMessage = JSON::Object::create();
5665 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5666}
5667
5668void NetworkBackendDispatcher::interceptRequestWithError(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5669{
5670 auto in_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, true);
5671 auto in_errorType_json = m_backendDispatcher->getString(protocol_parameters.get(), "errorType"_s, true);
5672 if (m_backendDispatcher->hasProtocolErrors()) {
5673 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Network.interceptRequestWithError' can't be processed"_s);
5674 return;
5675 }
5676
5677#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5678 if (m_alternateDispatcher) {
5679 m_alternateDispatcher->interceptRequestWithError(protocol_requestId, in_requestId, in_errorType_json);
5680 return;
5681 }
5682#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5683
5684 auto in_errorType = Protocol::Helpers::parseEnumValueFromString<Protocol::Network::ResourceErrorType>(in_errorType_json);
5685 if (!in_errorType) {
5686 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown errorType: "_s, in_errorType_json));
5687 return;
5688 }
5689
5690 auto result = m_agent->interceptRequestWithError(in_requestId, *in_errorType);
5691 if (!result) {
5692 ASSERT(!result.error().isEmpty());
5693 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5694 return;
5695 }
5696
5697 auto protocol_jsonMessage = JSON::Object::create();
5698 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5699}
5700
5701Ref<PageBackendDispatcher> PageBackendDispatcher::create(BackendDispatcher& backendDispatcher, PageBackendDispatcherHandler* agent)
5702{
5703 return adoptRef(*new PageBackendDispatcher(backendDispatcher, agent));
5704}
5705
5706PageBackendDispatcher::PageBackendDispatcher(BackendDispatcher& backendDispatcher, PageBackendDispatcherHandler* agent)
5707 : SupplementalBackendDispatcher(backendDispatcher)
5708 , m_agent(agent)
5709{
5710 m_backendDispatcher->registerDispatcherForDomain("Page"_s, this);
5711}
5712
5713void PageBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
5714{
5715 Ref<PageBackendDispatcher> protect(*this);
5716
5717 auto protocol_parameters = protocol_message->getObject("params"_s);
5718
5719 using CallHandler = void (PageBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
5720 using DispatchMap = HashMap<String, CallHandler>;
5721 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
5722 { "enable"_s, &PageBackendDispatcher::enable },
5723 { "disable"_s, &PageBackendDispatcher::disable },
5724 { "reload"_s, &PageBackendDispatcher::reload },
5725 { "navigate"_s, &PageBackendDispatcher::navigate },
5726 { "overrideUserAgent"_s, &PageBackendDispatcher::overrideUserAgent },
5727 { "overrideSetting"_s, &PageBackendDispatcher::overrideSetting },
5728 { "getCookies"_s, &PageBackendDispatcher::getCookies },
5729 { "setCookie"_s, &PageBackendDispatcher::setCookie },
5730 { "deleteCookie"_s, &PageBackendDispatcher::deleteCookie },
5731 { "getResourceTree"_s, &PageBackendDispatcher::getResourceTree },
5732 { "getResourceContent"_s, &PageBackendDispatcher::getResourceContent },
5733 { "setBootstrapScript"_s, &PageBackendDispatcher::setBootstrapScript },
5734 { "searchInResource"_s, &PageBackendDispatcher::searchInResource },
5735 { "searchInResources"_s, &PageBackendDispatcher::searchInResources },
5736#if !(defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
5737 { "setShowRulers"_s, &PageBackendDispatcher::setShowRulers },
5738#endif // !(defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
5739 { "setShowPaintRects"_s, &PageBackendDispatcher::setShowPaintRects },
5740 { "setEmulatedMedia"_s, &PageBackendDispatcher::setEmulatedMedia },
5741#if (defined(ENABLE_DARK_MODE_CSS) && ENABLE_DARK_MODE_CSS) || (defined(HAVE_OS_DARK_MODE_SUPPORT) && HAVE_OS_DARK_MODE_SUPPORT)
5742 { "setForcedAppearance"_s, &PageBackendDispatcher::setForcedAppearance },
5743#endif // (defined(ENABLE_DARK_MODE_CSS) && ENABLE_DARK_MODE_CSS) || (defined(HAVE_OS_DARK_MODE_SUPPORT) && HAVE_OS_DARK_MODE_SUPPORT)
5744 { "snapshotNode"_s, &PageBackendDispatcher::snapshotNode },
5745 { "snapshotRect"_s, &PageBackendDispatcher::snapshotRect },
5746#if (defined(ENABLE_WEB_ARCHIVE) && ENABLE_WEB_ARCHIVE) && (defined(USE_CF) && USE_CF)
5747 { "archive"_s, &PageBackendDispatcher::archive },
5748#endif // (defined(ENABLE_WEB_ARCHIVE) && ENABLE_WEB_ARCHIVE) && (defined(USE_CF) && USE_CF)
5749#if !(defined(WTF_PLATFORM_COCOA) && WTF_PLATFORM_COCOA)
5750 { "setScreenSizeOverride"_s, &PageBackendDispatcher::setScreenSizeOverride },
5751#endif // !(defined(WTF_PLATFORM_COCOA) && WTF_PLATFORM_COCOA)
5752 });
5753
5754 auto findResult = dispatchMap->find(protocol_method);
5755 if (findResult == dispatchMap->end()) {
5756 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Page."_s, protocol_method, "' was not found"_s));
5757 return;
5758 }
5759
5760 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
5761}
5762
5763void PageBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
5764{
5765#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5766 if (m_alternateDispatcher) {
5767 m_alternateDispatcher->enable(protocol_requestId);
5768 return;
5769 }
5770#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5771
5772 auto result = m_agent->enable();
5773 if (!result) {
5774 ASSERT(!result.error().isEmpty());
5775 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5776 return;
5777 }
5778
5779 auto protocol_jsonMessage = JSON::Object::create();
5780 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5781}
5782
5783void PageBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
5784{
5785#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5786 if (m_alternateDispatcher) {
5787 m_alternateDispatcher->disable(protocol_requestId);
5788 return;
5789 }
5790#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5791
5792 auto result = m_agent->disable();
5793 if (!result) {
5794 ASSERT(!result.error().isEmpty());
5795 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5796 return;
5797 }
5798
5799 auto protocol_jsonMessage = JSON::Object::create();
5800 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5801}
5802
5803void PageBackendDispatcher::reload(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5804{
5805 auto in_opt_ignoreCache = m_backendDispatcher->getBoolean(protocol_parameters.get(), "ignoreCache"_s, false);
5806 auto in_opt_revalidateAllResources = m_backendDispatcher->getBoolean(protocol_parameters.get(), "revalidateAllResources"_s, false);
5807 if (m_backendDispatcher->hasProtocolErrors()) {
5808 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.reload' can't be processed"_s);
5809 return;
5810 }
5811
5812#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5813 if (m_alternateDispatcher) {
5814 m_alternateDispatcher->reload(protocol_requestId, WTFMove(in_opt_ignoreCache), WTFMove(in_opt_revalidateAllResources));
5815 return;
5816 }
5817#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5818
5819 auto result = m_agent->reload(WTFMove(in_opt_ignoreCache), WTFMove(in_opt_revalidateAllResources));
5820 if (!result) {
5821 ASSERT(!result.error().isEmpty());
5822 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5823 return;
5824 }
5825
5826 auto protocol_jsonMessage = JSON::Object::create();
5827 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5828}
5829
5830void PageBackendDispatcher::navigate(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5831{
5832 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
5833 if (m_backendDispatcher->hasProtocolErrors()) {
5834 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.navigate' can't be processed"_s);
5835 return;
5836 }
5837
5838#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5839 if (m_alternateDispatcher) {
5840 m_alternateDispatcher->navigate(protocol_requestId, in_url);
5841 return;
5842 }
5843#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5844
5845 auto result = m_agent->navigate(in_url);
5846 if (!result) {
5847 ASSERT(!result.error().isEmpty());
5848 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5849 return;
5850 }
5851
5852 auto protocol_jsonMessage = JSON::Object::create();
5853 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5854}
5855
5856void PageBackendDispatcher::overrideUserAgent(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5857{
5858 auto in_opt_value = m_backendDispatcher->getString(protocol_parameters.get(), "value"_s, false);
5859 if (m_backendDispatcher->hasProtocolErrors()) {
5860 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.overrideUserAgent' can't be processed"_s);
5861 return;
5862 }
5863
5864#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5865 if (m_alternateDispatcher) {
5866 m_alternateDispatcher->overrideUserAgent(protocol_requestId, in_opt_value);
5867 return;
5868 }
5869#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5870
5871 auto result = m_agent->overrideUserAgent(in_opt_value);
5872 if (!result) {
5873 ASSERT(!result.error().isEmpty());
5874 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5875 return;
5876 }
5877
5878 auto protocol_jsonMessage = JSON::Object::create();
5879 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5880}
5881
5882void PageBackendDispatcher::overrideSetting(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5883{
5884 auto in_setting_json = m_backendDispatcher->getString(protocol_parameters.get(), "setting"_s, true);
5885 auto in_opt_value = m_backendDispatcher->getBoolean(protocol_parameters.get(), "value"_s, false);
5886 if (m_backendDispatcher->hasProtocolErrors()) {
5887 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.overrideSetting' can't be processed"_s);
5888 return;
5889 }
5890
5891#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5892 if (m_alternateDispatcher) {
5893 m_alternateDispatcher->overrideSetting(protocol_requestId, in_setting_json, WTFMove(in_opt_value));
5894 return;
5895 }
5896#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5897
5898 auto in_setting = Protocol::Helpers::parseEnumValueFromString<Protocol::Page::Setting>(in_setting_json);
5899 if (!in_setting) {
5900 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown setting: "_s, in_setting_json));
5901 return;
5902 }
5903
5904 auto result = m_agent->overrideSetting(*in_setting, WTFMove(in_opt_value));
5905 if (!result) {
5906 ASSERT(!result.error().isEmpty());
5907 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5908 return;
5909 }
5910
5911 auto protocol_jsonMessage = JSON::Object::create();
5912 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5913}
5914
5915void PageBackendDispatcher::getCookies(long protocol_requestId, RefPtr<JSON::Object>&&)
5916{
5917#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5918 if (m_alternateDispatcher) {
5919 m_alternateDispatcher->getCookies(protocol_requestId);
5920 return;
5921 }
5922#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5923
5924 auto result = m_agent->getCookies();
5925 if (!result) {
5926 ASSERT(!result.error().isEmpty());
5927 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5928 return;
5929 }
5930
5931 auto out_cookies = WTFMove(result.value());
5932
5933 auto protocol_jsonMessage = JSON::Object::create();
5934 protocol_jsonMessage->setArray("cookies"_s, WTFMove(out_cookies));
5935 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5936}
5937
5938void PageBackendDispatcher::setCookie(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5939{
5940 auto in_cookie = m_backendDispatcher->getObject(protocol_parameters.get(), "cookie"_s, true);
5941 if (m_backendDispatcher->hasProtocolErrors()) {
5942 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setCookie' can't be processed"_s);
5943 return;
5944 }
5945
5946#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5947 if (m_alternateDispatcher) {
5948 m_alternateDispatcher->setCookie(protocol_requestId, in_cookie.releaseNonNull());
5949 return;
5950 }
5951#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5952
5953 auto result = m_agent->setCookie(in_cookie.releaseNonNull());
5954 if (!result) {
5955 ASSERT(!result.error().isEmpty());
5956 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5957 return;
5958 }
5959
5960 auto protocol_jsonMessage = JSON::Object::create();
5961 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5962}
5963
5964void PageBackendDispatcher::deleteCookie(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
5965{
5966 auto in_cookieName = m_backendDispatcher->getString(protocol_parameters.get(), "cookieName"_s, true);
5967 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
5968 if (m_backendDispatcher->hasProtocolErrors()) {
5969 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.deleteCookie' can't be processed"_s);
5970 return;
5971 }
5972
5973#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5974 if (m_alternateDispatcher) {
5975 m_alternateDispatcher->deleteCookie(protocol_requestId, in_cookieName, in_url);
5976 return;
5977 }
5978#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5979
5980 auto result = m_agent->deleteCookie(in_cookieName, in_url);
5981 if (!result) {
5982 ASSERT(!result.error().isEmpty());
5983 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
5984 return;
5985 }
5986
5987 auto protocol_jsonMessage = JSON::Object::create();
5988 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
5989}
5990
5991void PageBackendDispatcher::getResourceTree(long protocol_requestId, RefPtr<JSON::Object>&&)
5992{
5993#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5994 if (m_alternateDispatcher) {
5995 m_alternateDispatcher->getResourceTree(protocol_requestId);
5996 return;
5997 }
5998#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
5999
6000 auto result = m_agent->getResourceTree();
6001 if (!result) {
6002 ASSERT(!result.error().isEmpty());
6003 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6004 return;
6005 }
6006
6007 auto out_frameTree = WTFMove(result.value());
6008
6009 auto protocol_jsonMessage = JSON::Object::create();
6010 protocol_jsonMessage->setObject("frameTree"_s, WTFMove(out_frameTree));
6011 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6012}
6013
6014void PageBackendDispatcher::getResourceContent(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6015{
6016 auto in_frameId = m_backendDispatcher->getString(protocol_parameters.get(), "frameId"_s, true);
6017 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
6018 if (m_backendDispatcher->hasProtocolErrors()) {
6019 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.getResourceContent' can't be processed"_s);
6020 return;
6021 }
6022
6023#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6024 if (m_alternateDispatcher) {
6025 m_alternateDispatcher->getResourceContent(protocol_requestId, in_frameId, in_url);
6026 return;
6027 }
6028#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6029
6030 auto result = m_agent->getResourceContent(in_frameId, in_url);
6031 if (!result) {
6032 ASSERT(!result.error().isEmpty());
6033 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6034 return;
6035 }
6036
6037 auto [out_content, out_base64Encoded] = WTFMove(result.value());
6038
6039 auto protocol_jsonMessage = JSON::Object::create();
6040 protocol_jsonMessage->setString("content"_s, out_content);
6041 protocol_jsonMessage->setBoolean("base64Encoded"_s, out_base64Encoded);
6042 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6043}
6044
6045void PageBackendDispatcher::setBootstrapScript(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6046{
6047 auto in_opt_source = m_backendDispatcher->getString(protocol_parameters.get(), "source"_s, false);
6048 if (m_backendDispatcher->hasProtocolErrors()) {
6049 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setBootstrapScript' can't be processed"_s);
6050 return;
6051 }
6052
6053#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6054 if (m_alternateDispatcher) {
6055 m_alternateDispatcher->setBootstrapScript(protocol_requestId, in_opt_source);
6056 return;
6057 }
6058#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6059
6060 auto result = m_agent->setBootstrapScript(in_opt_source);
6061 if (!result) {
6062 ASSERT(!result.error().isEmpty());
6063 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6064 return;
6065 }
6066
6067 auto protocol_jsonMessage = JSON::Object::create();
6068 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6069}
6070
6071void PageBackendDispatcher::searchInResource(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6072{
6073 auto in_frameId = m_backendDispatcher->getString(protocol_parameters.get(), "frameId"_s, true);
6074 auto in_url = m_backendDispatcher->getString(protocol_parameters.get(), "url"_s, true);
6075 auto in_query = m_backendDispatcher->getString(protocol_parameters.get(), "query"_s, true);
6076 auto in_opt_caseSensitive = m_backendDispatcher->getBoolean(protocol_parameters.get(), "caseSensitive"_s, false);
6077 auto in_opt_isRegex = m_backendDispatcher->getBoolean(protocol_parameters.get(), "isRegex"_s, false);
6078 auto in_opt_requestId = m_backendDispatcher->getString(protocol_parameters.get(), "requestId"_s, false);
6079 if (m_backendDispatcher->hasProtocolErrors()) {
6080 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.searchInResource' can't be processed"_s);
6081 return;
6082 }
6083
6084#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6085 if (m_alternateDispatcher) {
6086 m_alternateDispatcher->searchInResource(protocol_requestId, in_frameId, in_url, in_query, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex), in_opt_requestId);
6087 return;
6088 }
6089#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6090
6091 auto result = m_agent->searchInResource(in_frameId, in_url, in_query, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex), in_opt_requestId);
6092 if (!result) {
6093 ASSERT(!result.error().isEmpty());
6094 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6095 return;
6096 }
6097
6098 auto out_result = WTFMove(result.value());
6099
6100 auto protocol_jsonMessage = JSON::Object::create();
6101 protocol_jsonMessage->setArray("result"_s, WTFMove(out_result));
6102 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6103}
6104
6105void PageBackendDispatcher::searchInResources(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6106{
6107 auto in_text = m_backendDispatcher->getString(protocol_parameters.get(), "text"_s, true);
6108 auto in_opt_caseSensitive = m_backendDispatcher->getBoolean(protocol_parameters.get(), "caseSensitive"_s, false);
6109 auto in_opt_isRegex = m_backendDispatcher->getBoolean(protocol_parameters.get(), "isRegex"_s, false);
6110 if (m_backendDispatcher->hasProtocolErrors()) {
6111 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.searchInResources' can't be processed"_s);
6112 return;
6113 }
6114
6115#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6116 if (m_alternateDispatcher) {
6117 m_alternateDispatcher->searchInResources(protocol_requestId, in_text, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
6118 return;
6119 }
6120#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6121
6122 auto result = m_agent->searchInResources(in_text, WTFMove(in_opt_caseSensitive), WTFMove(in_opt_isRegex));
6123 if (!result) {
6124 ASSERT(!result.error().isEmpty());
6125 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6126 return;
6127 }
6128
6129 auto out_result = WTFMove(result.value());
6130
6131 auto protocol_jsonMessage = JSON::Object::create();
6132 protocol_jsonMessage->setArray("result"_s, WTFMove(out_result));
6133 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6134}
6135
6136#if !(defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
6137void PageBackendDispatcher::setShowRulers(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6138{
6139 auto in_result = m_backendDispatcher->getBoolean(protocol_parameters.get(), "result"_s, true);
6140 if (m_backendDispatcher->hasProtocolErrors()) {
6141 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setShowRulers' can't be processed"_s);
6142 return;
6143 }
6144
6145#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6146 if (m_alternateDispatcher) {
6147 m_alternateDispatcher->setShowRulers(protocol_requestId, *in_result);
6148 return;
6149 }
6150#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6151
6152 auto result = m_agent->setShowRulers(*in_result);
6153 if (!result) {
6154 ASSERT(!result.error().isEmpty());
6155 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6156 return;
6157 }
6158
6159 auto protocol_jsonMessage = JSON::Object::create();
6160 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6161}
6162#endif // !(defined(WTF_PLATFORM_IOS_FAMILY) && WTF_PLATFORM_IOS_FAMILY)
6163
6164void PageBackendDispatcher::setShowPaintRects(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6165{
6166 auto in_result = m_backendDispatcher->getBoolean(protocol_parameters.get(), "result"_s, true);
6167 if (m_backendDispatcher->hasProtocolErrors()) {
6168 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setShowPaintRects' can't be processed"_s);
6169 return;
6170 }
6171
6172#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6173 if (m_alternateDispatcher) {
6174 m_alternateDispatcher->setShowPaintRects(protocol_requestId, *in_result);
6175 return;
6176 }
6177#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6178
6179 auto result = m_agent->setShowPaintRects(*in_result);
6180 if (!result) {
6181 ASSERT(!result.error().isEmpty());
6182 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6183 return;
6184 }
6185
6186 auto protocol_jsonMessage = JSON::Object::create();
6187 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6188}
6189
6190void PageBackendDispatcher::setEmulatedMedia(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6191{
6192 auto in_media = m_backendDispatcher->getString(protocol_parameters.get(), "media"_s, true);
6193 if (m_backendDispatcher->hasProtocolErrors()) {
6194 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setEmulatedMedia' can't be processed"_s);
6195 return;
6196 }
6197
6198#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6199 if (m_alternateDispatcher) {
6200 m_alternateDispatcher->setEmulatedMedia(protocol_requestId, in_media);
6201 return;
6202 }
6203#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6204
6205 auto result = m_agent->setEmulatedMedia(in_media);
6206 if (!result) {
6207 ASSERT(!result.error().isEmpty());
6208 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6209 return;
6210 }
6211
6212 auto protocol_jsonMessage = JSON::Object::create();
6213 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6214}
6215
6216#if (defined(ENABLE_DARK_MODE_CSS) && ENABLE_DARK_MODE_CSS) || (defined(HAVE_OS_DARK_MODE_SUPPORT) && HAVE_OS_DARK_MODE_SUPPORT)
6217void PageBackendDispatcher::setForcedAppearance(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6218{
6219 auto in_opt_appearance_json = m_backendDispatcher->getString(protocol_parameters.get(), "appearance"_s, false);
6220 if (m_backendDispatcher->hasProtocolErrors()) {
6221 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setForcedAppearance' can't be processed"_s);
6222 return;
6223 }
6224
6225#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6226 if (m_alternateDispatcher) {
6227 m_alternateDispatcher->setForcedAppearance(protocol_requestId, in_opt_appearance_json);
6228 return;
6229 }
6230#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6231
6232 auto in_opt_appearance = Protocol::Helpers::parseEnumValueFromString<Protocol::Page::Appearance>(in_opt_appearance_json);
6233
6234 auto result = m_agent->setForcedAppearance(WTFMove(in_opt_appearance));
6235 if (!result) {
6236 ASSERT(!result.error().isEmpty());
6237 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6238 return;
6239 }
6240
6241 auto protocol_jsonMessage = JSON::Object::create();
6242 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6243}
6244#endif // (defined(ENABLE_DARK_MODE_CSS) && ENABLE_DARK_MODE_CSS) || (defined(HAVE_OS_DARK_MODE_SUPPORT) && HAVE_OS_DARK_MODE_SUPPORT)
6245
6246void PageBackendDispatcher::snapshotNode(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6247{
6248 auto in_nodeId = m_backendDispatcher->getInteger(protocol_parameters.get(), "nodeId"_s, true);
6249 if (m_backendDispatcher->hasProtocolErrors()) {
6250 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.snapshotNode' can't be processed"_s);
6251 return;
6252 }
6253
6254#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6255 if (m_alternateDispatcher) {
6256 m_alternateDispatcher->snapshotNode(protocol_requestId, *in_nodeId);
6257 return;
6258 }
6259#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6260
6261 auto result = m_agent->snapshotNode(*in_nodeId);
6262 if (!result) {
6263 ASSERT(!result.error().isEmpty());
6264 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6265 return;
6266 }
6267
6268 auto out_dataURL = WTFMove(result.value());
6269
6270 auto protocol_jsonMessage = JSON::Object::create();
6271 protocol_jsonMessage->setString("dataURL"_s, out_dataURL);
6272 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6273}
6274
6275void PageBackendDispatcher::snapshotRect(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6276{
6277 auto in_x = m_backendDispatcher->getInteger(protocol_parameters.get(), "x"_s, true);
6278 auto in_y = m_backendDispatcher->getInteger(protocol_parameters.get(), "y"_s, true);
6279 auto in_width = m_backendDispatcher->getInteger(protocol_parameters.get(), "width"_s, true);
6280 auto in_height = m_backendDispatcher->getInteger(protocol_parameters.get(), "height"_s, true);
6281 auto in_coordinateSystem_json = m_backendDispatcher->getString(protocol_parameters.get(), "coordinateSystem"_s, true);
6282 if (m_backendDispatcher->hasProtocolErrors()) {
6283 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.snapshotRect' can't be processed"_s);
6284 return;
6285 }
6286
6287#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6288 if (m_alternateDispatcher) {
6289 m_alternateDispatcher->snapshotRect(protocol_requestId, *in_x, *in_y, *in_width, *in_height, in_coordinateSystem_json);
6290 return;
6291 }
6292#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6293
6294 auto in_coordinateSystem = Protocol::Helpers::parseEnumValueFromString<Protocol::Page::CoordinateSystem>(in_coordinateSystem_json);
6295 if (!in_coordinateSystem) {
6296 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, makeString("Unknown coordinateSystem: "_s, in_coordinateSystem_json));
6297 return;
6298 }
6299
6300 auto result = m_agent->snapshotRect(*in_x, *in_y, *in_width, *in_height, *in_coordinateSystem);
6301 if (!result) {
6302 ASSERT(!result.error().isEmpty());
6303 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6304 return;
6305 }
6306
6307 auto out_dataURL = WTFMove(result.value());
6308
6309 auto protocol_jsonMessage = JSON::Object::create();
6310 protocol_jsonMessage->setString("dataURL"_s, out_dataURL);
6311 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6312}
6313
6314#if (defined(ENABLE_WEB_ARCHIVE) && ENABLE_WEB_ARCHIVE) && (defined(USE_CF) && USE_CF)
6315void PageBackendDispatcher::archive(long protocol_requestId, RefPtr<JSON::Object>&&)
6316{
6317#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6318 if (m_alternateDispatcher) {
6319 m_alternateDispatcher->archive(protocol_requestId);
6320 return;
6321 }
6322#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6323
6324 auto result = m_agent->archive();
6325 if (!result) {
6326 ASSERT(!result.error().isEmpty());
6327 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6328 return;
6329 }
6330
6331 auto out_data = WTFMove(result.value());
6332
6333 auto protocol_jsonMessage = JSON::Object::create();
6334 protocol_jsonMessage->setString("data"_s, out_data);
6335 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6336}
6337#endif // (defined(ENABLE_WEB_ARCHIVE) && ENABLE_WEB_ARCHIVE) && (defined(USE_CF) && USE_CF)
6338
6339#if !(defined(WTF_PLATFORM_COCOA) && WTF_PLATFORM_COCOA)
6340void PageBackendDispatcher::setScreenSizeOverride(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6341{
6342 auto in_opt_width = m_backendDispatcher->getInteger(protocol_parameters.get(), "width"_s, false);
6343 auto in_opt_height = m_backendDispatcher->getInteger(protocol_parameters.get(), "height"_s, false);
6344 if (m_backendDispatcher->hasProtocolErrors()) {
6345 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Page.setScreenSizeOverride' can't be processed"_s);
6346 return;
6347 }
6348
6349#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6350 if (m_alternateDispatcher) {
6351 m_alternateDispatcher->setScreenSizeOverride(protocol_requestId, WTFMove(in_opt_width), WTFMove(in_opt_height));
6352 return;
6353 }
6354#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6355
6356 auto result = m_agent->setScreenSizeOverride(WTFMove(in_opt_width), WTFMove(in_opt_height));
6357 if (!result) {
6358 ASSERT(!result.error().isEmpty());
6359 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6360 return;
6361 }
6362
6363 auto protocol_jsonMessage = JSON::Object::create();
6364 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6365}
6366#endif // !(defined(WTF_PLATFORM_COCOA) && WTF_PLATFORM_COCOA)
6367
6368Ref<RuntimeBackendDispatcher> RuntimeBackendDispatcher::create(BackendDispatcher& backendDispatcher, RuntimeBackendDispatcherHandler* agent)
6369{
6370 return adoptRef(*new RuntimeBackendDispatcher(backendDispatcher, agent));
6371}
6372
6373RuntimeBackendDispatcher::RuntimeBackendDispatcher(BackendDispatcher& backendDispatcher, RuntimeBackendDispatcherHandler* agent)
6374 : SupplementalBackendDispatcher(backendDispatcher)
6375 , m_agent(agent)
6376{
6377 m_backendDispatcher->registerDispatcherForDomain("Runtime"_s, this);
6378}
6379
6380void RuntimeBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
6381{
6382 Ref<RuntimeBackendDispatcher> protect(*this);
6383
6384 auto protocol_parameters = protocol_message->getObject("params"_s);
6385
6386 using CallHandler = void (RuntimeBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
6387 using DispatchMap = HashMap<String, CallHandler>;
6388 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
6389 { "parse"_s, &RuntimeBackendDispatcher::parse },
6390 { "evaluate"_s, &RuntimeBackendDispatcher::evaluate },
6391 { "awaitPromise"_s, &RuntimeBackendDispatcher::awaitPromise },
6392 { "callFunctionOn"_s, &RuntimeBackendDispatcher::callFunctionOn },
6393 { "getPreview"_s, &RuntimeBackendDispatcher::getPreview },
6394 { "getProperties"_s, &RuntimeBackendDispatcher::getProperties },
6395 { "getDisplayableProperties"_s, &RuntimeBackendDispatcher::getDisplayableProperties },
6396 { "getCollectionEntries"_s, &RuntimeBackendDispatcher::getCollectionEntries },
6397 { "saveResult"_s, &RuntimeBackendDispatcher::saveResult },
6398 { "setSavedResultAlias"_s, &RuntimeBackendDispatcher::setSavedResultAlias },
6399 { "releaseObject"_s, &RuntimeBackendDispatcher::releaseObject },
6400 { "releaseObjectGroup"_s, &RuntimeBackendDispatcher::releaseObjectGroup },
6401 { "enable"_s, &RuntimeBackendDispatcher::enable },
6402 { "disable"_s, &RuntimeBackendDispatcher::disable },
6403 { "getRuntimeTypesForVariablesAtOffsets"_s, &RuntimeBackendDispatcher::getRuntimeTypesForVariablesAtOffsets },
6404 { "enableTypeProfiler"_s, &RuntimeBackendDispatcher::enableTypeProfiler },
6405 { "disableTypeProfiler"_s, &RuntimeBackendDispatcher::disableTypeProfiler },
6406 { "enableControlFlowProfiler"_s, &RuntimeBackendDispatcher::enableControlFlowProfiler },
6407 { "disableControlFlowProfiler"_s, &RuntimeBackendDispatcher::disableControlFlowProfiler },
6408 { "getBasicBlocks"_s, &RuntimeBackendDispatcher::getBasicBlocks },
6409 });
6410
6411 auto findResult = dispatchMap->find(protocol_method);
6412 if (findResult == dispatchMap->end()) {
6413 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Runtime."_s, protocol_method, "' was not found"_s));
6414 return;
6415 }
6416
6417 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
6418}
6419
6420void RuntimeBackendDispatcher::parse(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6421{
6422 auto in_source = m_backendDispatcher->getString(protocol_parameters.get(), "source"_s, true);
6423 if (m_backendDispatcher->hasProtocolErrors()) {
6424 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.parse' can't be processed"_s);
6425 return;
6426 }
6427
6428#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6429 if (m_alternateDispatcher) {
6430 m_alternateDispatcher->parse(protocol_requestId, in_source);
6431 return;
6432 }
6433#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6434
6435 auto result = m_agent->parse(in_source);
6436 if (!result) {
6437 ASSERT(!result.error().isEmpty());
6438 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6439 return;
6440 }
6441
6442 auto [out_result, out_opt_message, out_opt_range] = WTFMove(result.value());
6443
6444 auto protocol_jsonMessage = JSON::Object::create();
6445 protocol_jsonMessage->setString("result"_s, Protocol::Helpers::getEnumConstantValue(out_result));
6446 if (!!out_opt_message)
6447 protocol_jsonMessage->setString("message"_s, out_opt_message);
6448 if (!!out_opt_range)
6449 protocol_jsonMessage->setObject("range"_s, out_opt_range.releaseNonNull());
6450 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6451}
6452
6453void RuntimeBackendDispatcher::evaluate(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6454{
6455 auto in_expression = m_backendDispatcher->getString(protocol_parameters.get(), "expression"_s, true);
6456 auto in_opt_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, false);
6457 auto in_opt_includeCommandLineAPI = m_backendDispatcher->getBoolean(protocol_parameters.get(), "includeCommandLineAPI"_s, false);
6458 auto in_opt_doNotPauseOnExceptionsAndMuteConsole = m_backendDispatcher->getBoolean(protocol_parameters.get(), "doNotPauseOnExceptionsAndMuteConsole"_s, false);
6459 auto in_opt_contextId = m_backendDispatcher->getInteger(protocol_parameters.get(), "contextId"_s, false);
6460 auto in_opt_returnByValue = m_backendDispatcher->getBoolean(protocol_parameters.get(), "returnByValue"_s, false);
6461 auto in_opt_generatePreview = m_backendDispatcher->getBoolean(protocol_parameters.get(), "generatePreview"_s, false);
6462 auto in_opt_saveResult = m_backendDispatcher->getBoolean(protocol_parameters.get(), "saveResult"_s, false);
6463 auto in_opt_emulateUserGesture = m_backendDispatcher->getBoolean(protocol_parameters.get(), "emulateUserGesture"_s, false);
6464 if (m_backendDispatcher->hasProtocolErrors()) {
6465 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.evaluate' can't be processed"_s);
6466 return;
6467 }
6468
6469#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6470 if (m_alternateDispatcher) {
6471 m_alternateDispatcher->evaluate(protocol_requestId, in_expression, in_opt_objectGroup, WTFMove(in_opt_includeCommandLineAPI), WTFMove(in_opt_doNotPauseOnExceptionsAndMuteConsole), WTFMove(in_opt_contextId), WTFMove(in_opt_returnByValue), WTFMove(in_opt_generatePreview), WTFMove(in_opt_saveResult), WTFMove(in_opt_emulateUserGesture));
6472 return;
6473 }
6474#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6475
6476 auto result = m_agent->evaluate(in_expression, in_opt_objectGroup, WTFMove(in_opt_includeCommandLineAPI), WTFMove(in_opt_doNotPauseOnExceptionsAndMuteConsole), WTFMove(in_opt_contextId), WTFMove(in_opt_returnByValue), WTFMove(in_opt_generatePreview), WTFMove(in_opt_saveResult), WTFMove(in_opt_emulateUserGesture));
6477 if (!result) {
6478 ASSERT(!result.error().isEmpty());
6479 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6480 return;
6481 }
6482
6483 auto [out_result, out_opt_wasThrown, out_opt_savedResultIndex] = WTFMove(result.value());
6484
6485 auto protocol_jsonMessage = JSON::Object::create();
6486 protocol_jsonMessage->setObject("result"_s, WTFMove(out_result));
6487 if (!!out_opt_wasThrown)
6488 protocol_jsonMessage->setBoolean("wasThrown"_s, *out_opt_wasThrown);
6489 if (!!out_opt_savedResultIndex)
6490 protocol_jsonMessage->setInteger("savedResultIndex"_s, *out_opt_savedResultIndex);
6491 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6492}
6493
6494RuntimeBackendDispatcherHandler::AwaitPromiseCallback::AwaitPromiseCallback(Ref<BackendDispatcher>&& backendDispatcher, int id) : BackendDispatcher::CallbackBase(WTFMove(backendDispatcher), id) { }
6495
6496void RuntimeBackendDispatcherHandler::AwaitPromiseCallback::sendSuccess(Ref<Protocol::Runtime::RemoteObject>&& result, std::optional<bool>&& opt_wasThrown, std::optional<int>&& opt_savedResultIndex)
6497{
6498 auto protocol_jsonMessage = JSON::Object::create();
6499 protocol_jsonMessage->setObject("result"_s, WTFMove(result));
6500 if (!!opt_wasThrown)
6501 protocol_jsonMessage->setBoolean("wasThrown"_s, *opt_wasThrown);
6502 if (!!opt_savedResultIndex)
6503 protocol_jsonMessage->setInteger("savedResultIndex"_s, *opt_savedResultIndex);
6504 CallbackBase::sendSuccess(WTFMove(protocol_jsonMessage));
6505}
6506
6507void RuntimeBackendDispatcher::awaitPromise(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6508{
6509 auto in_promiseObjectId = m_backendDispatcher->getString(protocol_parameters.get(), "promiseObjectId"_s, true);
6510 auto in_opt_returnByValue = m_backendDispatcher->getBoolean(protocol_parameters.get(), "returnByValue"_s, false);
6511 auto in_opt_generatePreview = m_backendDispatcher->getBoolean(protocol_parameters.get(), "generatePreview"_s, false);
6512 auto in_opt_saveResult = m_backendDispatcher->getBoolean(protocol_parameters.get(), "saveResult"_s, false);
6513 if (m_backendDispatcher->hasProtocolErrors()) {
6514 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.awaitPromise' can't be processed"_s);
6515 return;
6516 }
6517
6518#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6519 if (m_alternateDispatcher) {
6520 m_alternateDispatcher->awaitPromise(protocol_requestId, in_promiseObjectId, WTFMove(in_opt_returnByValue), WTFMove(in_opt_generatePreview), WTFMove(in_opt_saveResult));
6521 return;
6522 }
6523#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6524
6525 m_agent->awaitPromise(in_promiseObjectId, WTFMove(in_opt_returnByValue), WTFMove(in_opt_generatePreview), WTFMove(in_opt_saveResult), adoptRef(*new RuntimeBackendDispatcherHandler::AwaitPromiseCallback(m_backendDispatcher.copyRef(), protocol_requestId)));
6526}
6527
6528void RuntimeBackendDispatcher::callFunctionOn(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6529{
6530 auto in_objectId = m_backendDispatcher->getString(protocol_parameters.get(), "objectId"_s, true);
6531 auto in_functionDeclaration = m_backendDispatcher->getString(protocol_parameters.get(), "functionDeclaration"_s, true);
6532 auto in_opt_arguments = m_backendDispatcher->getArray(protocol_parameters.get(), "arguments"_s, false);
6533 auto in_opt_doNotPauseOnExceptionsAndMuteConsole = m_backendDispatcher->getBoolean(protocol_parameters.get(), "doNotPauseOnExceptionsAndMuteConsole"_s, false);
6534 auto in_opt_returnByValue = m_backendDispatcher->getBoolean(protocol_parameters.get(), "returnByValue"_s, false);
6535 auto in_opt_generatePreview = m_backendDispatcher->getBoolean(protocol_parameters.get(), "generatePreview"_s, false);
6536 auto in_opt_emulateUserGesture = m_backendDispatcher->getBoolean(protocol_parameters.get(), "emulateUserGesture"_s, false);
6537 if (m_backendDispatcher->hasProtocolErrors()) {
6538 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.callFunctionOn' can't be processed"_s);
6539 return;
6540 }
6541
6542#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6543 if (m_alternateDispatcher) {
6544 m_alternateDispatcher->callFunctionOn(protocol_requestId, in_objectId, in_functionDeclaration, WTFMove(in_opt_arguments), WTFMove(in_opt_doNotPauseOnExceptionsAndMuteConsole), WTFMove(in_opt_returnByValue), WTFMove(in_opt_generatePreview), WTFMove(in_opt_emulateUserGesture));
6545 return;
6546 }
6547#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6548
6549 auto result = m_agent->callFunctionOn(in_objectId, in_functionDeclaration, WTFMove(in_opt_arguments), WTFMove(in_opt_doNotPauseOnExceptionsAndMuteConsole), WTFMove(in_opt_returnByValue), WTFMove(in_opt_generatePreview), WTFMove(in_opt_emulateUserGesture));
6550 if (!result) {
6551 ASSERT(!result.error().isEmpty());
6552 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6553 return;
6554 }
6555
6556 auto [out_result, out_opt_wasThrown] = WTFMove(result.value());
6557
6558 auto protocol_jsonMessage = JSON::Object::create();
6559 protocol_jsonMessage->setObject("result"_s, WTFMove(out_result));
6560 if (!!out_opt_wasThrown)
6561 protocol_jsonMessage->setBoolean("wasThrown"_s, *out_opt_wasThrown);
6562 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6563}
6564
6565void RuntimeBackendDispatcher::getPreview(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6566{
6567 auto in_objectId = m_backendDispatcher->getString(protocol_parameters.get(), "objectId"_s, true);
6568 if (m_backendDispatcher->hasProtocolErrors()) {
6569 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getPreview' can't be processed"_s);
6570 return;
6571 }
6572
6573#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6574 if (m_alternateDispatcher) {
6575 m_alternateDispatcher->getPreview(protocol_requestId, in_objectId);
6576 return;
6577 }
6578#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6579
6580 auto result = m_agent->getPreview(in_objectId);
6581 if (!result) {
6582 ASSERT(!result.error().isEmpty());
6583 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6584 return;
6585 }
6586
6587 auto out_preview = WTFMove(result.value());
6588
6589 auto protocol_jsonMessage = JSON::Object::create();
6590 protocol_jsonMessage->setObject("preview"_s, WTFMove(out_preview));
6591 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6592}
6593
6594void RuntimeBackendDispatcher::getProperties(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6595{
6596 auto in_objectId = m_backendDispatcher->getString(protocol_parameters.get(), "objectId"_s, true);
6597 auto in_opt_ownProperties = m_backendDispatcher->getBoolean(protocol_parameters.get(), "ownProperties"_s, false);
6598 auto in_opt_fetchStart = m_backendDispatcher->getInteger(protocol_parameters.get(), "fetchStart"_s, false);
6599 auto in_opt_fetchCount = m_backendDispatcher->getInteger(protocol_parameters.get(), "fetchCount"_s, false);
6600 auto in_opt_generatePreview = m_backendDispatcher->getBoolean(protocol_parameters.get(), "generatePreview"_s, false);
6601 if (m_backendDispatcher->hasProtocolErrors()) {
6602 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getProperties' can't be processed"_s);
6603 return;
6604 }
6605
6606#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6607 if (m_alternateDispatcher) {
6608 m_alternateDispatcher->getProperties(protocol_requestId, in_objectId, WTFMove(in_opt_ownProperties), WTFMove(in_opt_fetchStart), WTFMove(in_opt_fetchCount), WTFMove(in_opt_generatePreview));
6609 return;
6610 }
6611#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6612
6613 auto result = m_agent->getProperties(in_objectId, WTFMove(in_opt_ownProperties), WTFMove(in_opt_fetchStart), WTFMove(in_opt_fetchCount), WTFMove(in_opt_generatePreview));
6614 if (!result) {
6615 ASSERT(!result.error().isEmpty());
6616 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6617 return;
6618 }
6619
6620 auto [out_properties, out_opt_internalProperties] = WTFMove(result.value());
6621
6622 auto protocol_jsonMessage = JSON::Object::create();
6623 protocol_jsonMessage->setArray("properties"_s, WTFMove(out_properties));
6624 if (!!out_opt_internalProperties)
6625 protocol_jsonMessage->setArray("internalProperties"_s, out_opt_internalProperties.releaseNonNull());
6626 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6627}
6628
6629void RuntimeBackendDispatcher::getDisplayableProperties(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6630{
6631 auto in_objectId = m_backendDispatcher->getString(protocol_parameters.get(), "objectId"_s, true);
6632 auto in_opt_fetchStart = m_backendDispatcher->getInteger(protocol_parameters.get(), "fetchStart"_s, false);
6633 auto in_opt_fetchCount = m_backendDispatcher->getInteger(protocol_parameters.get(), "fetchCount"_s, false);
6634 auto in_opt_generatePreview = m_backendDispatcher->getBoolean(protocol_parameters.get(), "generatePreview"_s, false);
6635 if (m_backendDispatcher->hasProtocolErrors()) {
6636 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getDisplayableProperties' can't be processed"_s);
6637 return;
6638 }
6639
6640#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6641 if (m_alternateDispatcher) {
6642 m_alternateDispatcher->getDisplayableProperties(protocol_requestId, in_objectId, WTFMove(in_opt_fetchStart), WTFMove(in_opt_fetchCount), WTFMove(in_opt_generatePreview));
6643 return;
6644 }
6645#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6646
6647 auto result = m_agent->getDisplayableProperties(in_objectId, WTFMove(in_opt_fetchStart), WTFMove(in_opt_fetchCount), WTFMove(in_opt_generatePreview));
6648 if (!result) {
6649 ASSERT(!result.error().isEmpty());
6650 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6651 return;
6652 }
6653
6654 auto [out_properties, out_opt_internalProperties] = WTFMove(result.value());
6655
6656 auto protocol_jsonMessage = JSON::Object::create();
6657 protocol_jsonMessage->setArray("properties"_s, WTFMove(out_properties));
6658 if (!!out_opt_internalProperties)
6659 protocol_jsonMessage->setArray("internalProperties"_s, out_opt_internalProperties.releaseNonNull());
6660 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6661}
6662
6663void RuntimeBackendDispatcher::getCollectionEntries(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6664{
6665 auto in_objectId = m_backendDispatcher->getString(protocol_parameters.get(), "objectId"_s, true);
6666 auto in_opt_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, false);
6667 auto in_opt_fetchStart = m_backendDispatcher->getInteger(protocol_parameters.get(), "fetchStart"_s, false);
6668 auto in_opt_fetchCount = m_backendDispatcher->getInteger(protocol_parameters.get(), "fetchCount"_s, false);
6669 if (m_backendDispatcher->hasProtocolErrors()) {
6670 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getCollectionEntries' can't be processed"_s);
6671 return;
6672 }
6673
6674#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6675 if (m_alternateDispatcher) {
6676 m_alternateDispatcher->getCollectionEntries(protocol_requestId, in_objectId, in_opt_objectGroup, WTFMove(in_opt_fetchStart), WTFMove(in_opt_fetchCount));
6677 return;
6678 }
6679#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6680
6681 auto result = m_agent->getCollectionEntries(in_objectId, in_opt_objectGroup, WTFMove(in_opt_fetchStart), WTFMove(in_opt_fetchCount));
6682 if (!result) {
6683 ASSERT(!result.error().isEmpty());
6684 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6685 return;
6686 }
6687
6688 auto out_entries = WTFMove(result.value());
6689
6690 auto protocol_jsonMessage = JSON::Object::create();
6691 protocol_jsonMessage->setArray("entries"_s, WTFMove(out_entries));
6692 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6693}
6694
6695void RuntimeBackendDispatcher::saveResult(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6696{
6697 auto in_value = m_backendDispatcher->getObject(protocol_parameters.get(), "value"_s, true);
6698 auto in_opt_contextId = m_backendDispatcher->getInteger(protocol_parameters.get(), "contextId"_s, false);
6699 if (m_backendDispatcher->hasProtocolErrors()) {
6700 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.saveResult' can't be processed"_s);
6701 return;
6702 }
6703
6704#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6705 if (m_alternateDispatcher) {
6706 m_alternateDispatcher->saveResult(protocol_requestId, in_value.releaseNonNull(), WTFMove(in_opt_contextId));
6707 return;
6708 }
6709#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6710
6711 auto result = m_agent->saveResult(in_value.releaseNonNull(), WTFMove(in_opt_contextId));
6712 if (!result) {
6713 ASSERT(!result.error().isEmpty());
6714 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6715 return;
6716 }
6717
6718 auto out_opt_savedResultIndex = WTFMove(result.value());
6719
6720 auto protocol_jsonMessage = JSON::Object::create();
6721 if (!!out_opt_savedResultIndex)
6722 protocol_jsonMessage->setInteger("savedResultIndex"_s, *out_opt_savedResultIndex);
6723 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6724}
6725
6726void RuntimeBackendDispatcher::setSavedResultAlias(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6727{
6728 auto in_opt_alias = m_backendDispatcher->getString(protocol_parameters.get(), "alias"_s, false);
6729 if (m_backendDispatcher->hasProtocolErrors()) {
6730 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.setSavedResultAlias' can't be processed"_s);
6731 return;
6732 }
6733
6734#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6735 if (m_alternateDispatcher) {
6736 m_alternateDispatcher->setSavedResultAlias(protocol_requestId, in_opt_alias);
6737 return;
6738 }
6739#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6740
6741 auto result = m_agent->setSavedResultAlias(in_opt_alias);
6742 if (!result) {
6743 ASSERT(!result.error().isEmpty());
6744 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6745 return;
6746 }
6747
6748 auto protocol_jsonMessage = JSON::Object::create();
6749 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6750}
6751
6752void RuntimeBackendDispatcher::releaseObject(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6753{
6754 auto in_objectId = m_backendDispatcher->getString(protocol_parameters.get(), "objectId"_s, true);
6755 if (m_backendDispatcher->hasProtocolErrors()) {
6756 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.releaseObject' can't be processed"_s);
6757 return;
6758 }
6759
6760#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6761 if (m_alternateDispatcher) {
6762 m_alternateDispatcher->releaseObject(protocol_requestId, in_objectId);
6763 return;
6764 }
6765#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6766
6767 auto result = m_agent->releaseObject(in_objectId);
6768 if (!result) {
6769 ASSERT(!result.error().isEmpty());
6770 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6771 return;
6772 }
6773
6774 auto protocol_jsonMessage = JSON::Object::create();
6775 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6776}
6777
6778void RuntimeBackendDispatcher::releaseObjectGroup(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6779{
6780 auto in_objectGroup = m_backendDispatcher->getString(protocol_parameters.get(), "objectGroup"_s, true);
6781 if (m_backendDispatcher->hasProtocolErrors()) {
6782 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.releaseObjectGroup' can't be processed"_s);
6783 return;
6784 }
6785
6786#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6787 if (m_alternateDispatcher) {
6788 m_alternateDispatcher->releaseObjectGroup(protocol_requestId, in_objectGroup);
6789 return;
6790 }
6791#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6792
6793 auto result = m_agent->releaseObjectGroup(in_objectGroup);
6794 if (!result) {
6795 ASSERT(!result.error().isEmpty());
6796 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6797 return;
6798 }
6799
6800 auto protocol_jsonMessage = JSON::Object::create();
6801 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6802}
6803
6804void RuntimeBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
6805{
6806#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6807 if (m_alternateDispatcher) {
6808 m_alternateDispatcher->enable(protocol_requestId);
6809 return;
6810 }
6811#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6812
6813 auto result = m_agent->enable();
6814 if (!result) {
6815 ASSERT(!result.error().isEmpty());
6816 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6817 return;
6818 }
6819
6820 auto protocol_jsonMessage = JSON::Object::create();
6821 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6822}
6823
6824void RuntimeBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
6825{
6826#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6827 if (m_alternateDispatcher) {
6828 m_alternateDispatcher->disable(protocol_requestId);
6829 return;
6830 }
6831#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6832
6833 auto result = m_agent->disable();
6834 if (!result) {
6835 ASSERT(!result.error().isEmpty());
6836 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6837 return;
6838 }
6839
6840 auto protocol_jsonMessage = JSON::Object::create();
6841 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6842}
6843
6844void RuntimeBackendDispatcher::getRuntimeTypesForVariablesAtOffsets(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6845{
6846 auto in_locations = m_backendDispatcher->getArray(protocol_parameters.get(), "locations"_s, true);
6847 if (m_backendDispatcher->hasProtocolErrors()) {
6848 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getRuntimeTypesForVariablesAtOffsets' can't be processed"_s);
6849 return;
6850 }
6851
6852#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6853 if (m_alternateDispatcher) {
6854 m_alternateDispatcher->getRuntimeTypesForVariablesAtOffsets(protocol_requestId, in_locations.releaseNonNull());
6855 return;
6856 }
6857#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6858
6859 auto result = m_agent->getRuntimeTypesForVariablesAtOffsets(in_locations.releaseNonNull());
6860 if (!result) {
6861 ASSERT(!result.error().isEmpty());
6862 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6863 return;
6864 }
6865
6866 auto out_types = WTFMove(result.value());
6867
6868 auto protocol_jsonMessage = JSON::Object::create();
6869 protocol_jsonMessage->setArray("types"_s, WTFMove(out_types));
6870 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6871}
6872
6873void RuntimeBackendDispatcher::enableTypeProfiler(long protocol_requestId, RefPtr<JSON::Object>&&)
6874{
6875#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6876 if (m_alternateDispatcher) {
6877 m_alternateDispatcher->enableTypeProfiler(protocol_requestId);
6878 return;
6879 }
6880#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6881
6882 auto result = m_agent->enableTypeProfiler();
6883 if (!result) {
6884 ASSERT(!result.error().isEmpty());
6885 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6886 return;
6887 }
6888
6889 auto protocol_jsonMessage = JSON::Object::create();
6890 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6891}
6892
6893void RuntimeBackendDispatcher::disableTypeProfiler(long protocol_requestId, RefPtr<JSON::Object>&&)
6894{
6895#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6896 if (m_alternateDispatcher) {
6897 m_alternateDispatcher->disableTypeProfiler(protocol_requestId);
6898 return;
6899 }
6900#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6901
6902 auto result = m_agent->disableTypeProfiler();
6903 if (!result) {
6904 ASSERT(!result.error().isEmpty());
6905 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6906 return;
6907 }
6908
6909 auto protocol_jsonMessage = JSON::Object::create();
6910 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6911}
6912
6913void RuntimeBackendDispatcher::enableControlFlowProfiler(long protocol_requestId, RefPtr<JSON::Object>&&)
6914{
6915#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6916 if (m_alternateDispatcher) {
6917 m_alternateDispatcher->enableControlFlowProfiler(protocol_requestId);
6918 return;
6919 }
6920#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6921
6922 auto result = m_agent->enableControlFlowProfiler();
6923 if (!result) {
6924 ASSERT(!result.error().isEmpty());
6925 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6926 return;
6927 }
6928
6929 auto protocol_jsonMessage = JSON::Object::create();
6930 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6931}
6932
6933void RuntimeBackendDispatcher::disableControlFlowProfiler(long protocol_requestId, RefPtr<JSON::Object>&&)
6934{
6935#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6936 if (m_alternateDispatcher) {
6937 m_alternateDispatcher->disableControlFlowProfiler(protocol_requestId);
6938 return;
6939 }
6940#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6941
6942 auto result = m_agent->disableControlFlowProfiler();
6943 if (!result) {
6944 ASSERT(!result.error().isEmpty());
6945 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6946 return;
6947 }
6948
6949 auto protocol_jsonMessage = JSON::Object::create();
6950 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6951}
6952
6953void RuntimeBackendDispatcher::getBasicBlocks(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
6954{
6955 auto in_sourceID = m_backendDispatcher->getString(protocol_parameters.get(), "sourceID"_s, true);
6956 if (m_backendDispatcher->hasProtocolErrors()) {
6957 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Runtime.getBasicBlocks' can't be processed"_s);
6958 return;
6959 }
6960
6961#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6962 if (m_alternateDispatcher) {
6963 m_alternateDispatcher->getBasicBlocks(protocol_requestId, in_sourceID);
6964 return;
6965 }
6966#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
6967
6968 auto result = m_agent->getBasicBlocks(in_sourceID);
6969 if (!result) {
6970 ASSERT(!result.error().isEmpty());
6971 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
6972 return;
6973 }
6974
6975 auto out_basicBlocks = WTFMove(result.value());
6976
6977 auto protocol_jsonMessage = JSON::Object::create();
6978 protocol_jsonMessage->setArray("basicBlocks"_s, WTFMove(out_basicBlocks));
6979 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
6980}
6981
6982Ref<ScriptProfilerBackendDispatcher> ScriptProfilerBackendDispatcher::create(BackendDispatcher& backendDispatcher, ScriptProfilerBackendDispatcherHandler* agent)
6983{
6984 return adoptRef(*new ScriptProfilerBackendDispatcher(backendDispatcher, agent));
6985}
6986
6987ScriptProfilerBackendDispatcher::ScriptProfilerBackendDispatcher(BackendDispatcher& backendDispatcher, ScriptProfilerBackendDispatcherHandler* agent)
6988 : SupplementalBackendDispatcher(backendDispatcher)
6989 , m_agent(agent)
6990{
6991 m_backendDispatcher->registerDispatcherForDomain("ScriptProfiler"_s, this);
6992}
6993
6994void ScriptProfilerBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
6995{
6996 Ref<ScriptProfilerBackendDispatcher> protect(*this);
6997
6998 auto protocol_parameters = protocol_message->getObject("params"_s);
6999
7000 if (protocol_method == "startTracking"_s) {
7001 startTracking(protocol_requestId, WTFMove(protocol_parameters));
7002 return;
7003 }
7004 if (protocol_method == "stopTracking"_s) {
7005 stopTracking(protocol_requestId, WTFMove(protocol_parameters));
7006 return;
7007 }
7008
7009 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'ScriptProfiler."_s, protocol_method, "' was not found"_s));
7010}
7011
7012void ScriptProfilerBackendDispatcher::startTracking(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7013{
7014 auto in_opt_includeSamples = m_backendDispatcher->getBoolean(protocol_parameters.get(), "includeSamples"_s, false);
7015 if (m_backendDispatcher->hasProtocolErrors()) {
7016 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'ScriptProfiler.startTracking' can't be processed"_s);
7017 return;
7018 }
7019
7020#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7021 if (m_alternateDispatcher) {
7022 m_alternateDispatcher->startTracking(protocol_requestId, WTFMove(in_opt_includeSamples));
7023 return;
7024 }
7025#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7026
7027 auto result = m_agent->startTracking(WTFMove(in_opt_includeSamples));
7028 if (!result) {
7029 ASSERT(!result.error().isEmpty());
7030 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7031 return;
7032 }
7033
7034 auto protocol_jsonMessage = JSON::Object::create();
7035 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7036}
7037
7038void ScriptProfilerBackendDispatcher::stopTracking(long protocol_requestId, RefPtr<JSON::Object>&&)
7039{
7040#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7041 if (m_alternateDispatcher) {
7042 m_alternateDispatcher->stopTracking(protocol_requestId);
7043 return;
7044 }
7045#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7046
7047 auto result = m_agent->stopTracking();
7048 if (!result) {
7049 ASSERT(!result.error().isEmpty());
7050 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7051 return;
7052 }
7053
7054 auto protocol_jsonMessage = JSON::Object::create();
7055 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7056}
7057
7058#if defined(ENABLE_SERVICE_WORKER) && ENABLE_SERVICE_WORKER
7059Ref<ServiceWorkerBackendDispatcher> ServiceWorkerBackendDispatcher::create(BackendDispatcher& backendDispatcher, ServiceWorkerBackendDispatcherHandler* agent)
7060{
7061 return adoptRef(*new ServiceWorkerBackendDispatcher(backendDispatcher, agent));
7062}
7063
7064ServiceWorkerBackendDispatcher::ServiceWorkerBackendDispatcher(BackendDispatcher& backendDispatcher, ServiceWorkerBackendDispatcherHandler* agent)
7065 : SupplementalBackendDispatcher(backendDispatcher)
7066 , m_agent(agent)
7067{
7068 m_backendDispatcher->registerDispatcherForDomain("ServiceWorker"_s, this);
7069}
7070
7071void ServiceWorkerBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
7072{
7073 Ref<ServiceWorkerBackendDispatcher> protect(*this);
7074
7075 auto protocol_parameters = protocol_message->getObject("params"_s);
7076
7077 if (protocol_method == "getInitializationInfo"_s) {
7078 getInitializationInfo(protocol_requestId, WTFMove(protocol_parameters));
7079 return;
7080 }
7081
7082 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'ServiceWorker."_s, protocol_method, "' was not found"_s));
7083}
7084
7085void ServiceWorkerBackendDispatcher::getInitializationInfo(long protocol_requestId, RefPtr<JSON::Object>&&)
7086{
7087#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7088 if (m_alternateDispatcher) {
7089 m_alternateDispatcher->getInitializationInfo(protocol_requestId);
7090 return;
7091 }
7092#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7093
7094 auto result = m_agent->getInitializationInfo();
7095 if (!result) {
7096 ASSERT(!result.error().isEmpty());
7097 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7098 return;
7099 }
7100
7101 auto out_info = WTFMove(result.value());
7102
7103 auto protocol_jsonMessage = JSON::Object::create();
7104 protocol_jsonMessage->setObject("info"_s, WTFMove(out_info));
7105 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7106}
7107#endif // defined(ENABLE_SERVICE_WORKER) && ENABLE_SERVICE_WORKER
7108
7109Ref<TargetBackendDispatcher> TargetBackendDispatcher::create(BackendDispatcher& backendDispatcher, TargetBackendDispatcherHandler* agent)
7110{
7111 return adoptRef(*new TargetBackendDispatcher(backendDispatcher, agent));
7112}
7113
7114TargetBackendDispatcher::TargetBackendDispatcher(BackendDispatcher& backendDispatcher, TargetBackendDispatcherHandler* agent)
7115 : SupplementalBackendDispatcher(backendDispatcher)
7116 , m_agent(agent)
7117{
7118 m_backendDispatcher->registerDispatcherForDomain("Target"_s, this);
7119}
7120
7121void TargetBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
7122{
7123 Ref<TargetBackendDispatcher> protect(*this);
7124
7125 auto protocol_parameters = protocol_message->getObject("params"_s);
7126
7127 if (protocol_method == "setPauseOnStart"_s) {
7128 setPauseOnStart(protocol_requestId, WTFMove(protocol_parameters));
7129 return;
7130 }
7131 if (protocol_method == "resume"_s) {
7132 resume(protocol_requestId, WTFMove(protocol_parameters));
7133 return;
7134 }
7135 if (protocol_method == "sendMessageToTarget"_s) {
7136 sendMessageToTarget(protocol_requestId, WTFMove(protocol_parameters));
7137 return;
7138 }
7139
7140 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Target."_s, protocol_method, "' was not found"_s));
7141}
7142
7143void TargetBackendDispatcher::setPauseOnStart(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7144{
7145 auto in_pauseOnStart = m_backendDispatcher->getBoolean(protocol_parameters.get(), "pauseOnStart"_s, true);
7146 if (m_backendDispatcher->hasProtocolErrors()) {
7147 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Target.setPauseOnStart' can't be processed"_s);
7148 return;
7149 }
7150
7151#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7152 if (m_alternateDispatcher) {
7153 m_alternateDispatcher->setPauseOnStart(protocol_requestId, *in_pauseOnStart);
7154 return;
7155 }
7156#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7157
7158 auto result = m_agent->setPauseOnStart(*in_pauseOnStart);
7159 if (!result) {
7160 ASSERT(!result.error().isEmpty());
7161 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7162 return;
7163 }
7164
7165 auto protocol_jsonMessage = JSON::Object::create();
7166 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7167}
7168
7169void TargetBackendDispatcher::resume(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7170{
7171 auto in_targetId = m_backendDispatcher->getString(protocol_parameters.get(), "targetId"_s, true);
7172 if (m_backendDispatcher->hasProtocolErrors()) {
7173 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Target.resume' can't be processed"_s);
7174 return;
7175 }
7176
7177#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7178 if (m_alternateDispatcher) {
7179 m_alternateDispatcher->resume(protocol_requestId, in_targetId);
7180 return;
7181 }
7182#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7183
7184 auto result = m_agent->resume(in_targetId);
7185 if (!result) {
7186 ASSERT(!result.error().isEmpty());
7187 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7188 return;
7189 }
7190
7191 auto protocol_jsonMessage = JSON::Object::create();
7192 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7193}
7194
7195void TargetBackendDispatcher::sendMessageToTarget(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7196{
7197 auto in_targetId = m_backendDispatcher->getString(protocol_parameters.get(), "targetId"_s, true);
7198 auto in_message = m_backendDispatcher->getString(protocol_parameters.get(), "message"_s, true);
7199 if (m_backendDispatcher->hasProtocolErrors()) {
7200 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Target.sendMessageToTarget' can't be processed"_s);
7201 return;
7202 }
7203
7204#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7205 if (m_alternateDispatcher) {
7206 m_alternateDispatcher->sendMessageToTarget(protocol_requestId, in_targetId, in_message);
7207 return;
7208 }
7209#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7210
7211 auto result = m_agent->sendMessageToTarget(in_targetId, in_message);
7212 if (!result) {
7213 ASSERT(!result.error().isEmpty());
7214 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7215 return;
7216 }
7217
7218 auto protocol_jsonMessage = JSON::Object::create();
7219 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7220}
7221
7222Ref<TimelineBackendDispatcher> TimelineBackendDispatcher::create(BackendDispatcher& backendDispatcher, TimelineBackendDispatcherHandler* agent)
7223{
7224 return adoptRef(*new TimelineBackendDispatcher(backendDispatcher, agent));
7225}
7226
7227TimelineBackendDispatcher::TimelineBackendDispatcher(BackendDispatcher& backendDispatcher, TimelineBackendDispatcherHandler* agent)
7228 : SupplementalBackendDispatcher(backendDispatcher)
7229 , m_agent(agent)
7230{
7231 m_backendDispatcher->registerDispatcherForDomain("Timeline"_s, this);
7232}
7233
7234void TimelineBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
7235{
7236 Ref<TimelineBackendDispatcher> protect(*this);
7237
7238 auto protocol_parameters = protocol_message->getObject("params"_s);
7239
7240 using CallHandler = void (TimelineBackendDispatcher::*)(long protocol_requestId, RefPtr<JSON::Object>&& protocol_message);
7241 using DispatchMap = HashMap<String, CallHandler>;
7242 static NeverDestroyed<DispatchMap> dispatchMap = DispatchMap({
7243 { "enable"_s, &TimelineBackendDispatcher::enable },
7244 { "disable"_s, &TimelineBackendDispatcher::disable },
7245 { "start"_s, &TimelineBackendDispatcher::start },
7246 { "stop"_s, &TimelineBackendDispatcher::stop },
7247 { "setAutoCaptureEnabled"_s, &TimelineBackendDispatcher::setAutoCaptureEnabled },
7248 { "setInstruments"_s, &TimelineBackendDispatcher::setInstruments },
7249 });
7250
7251 auto findResult = dispatchMap->find(protocol_method);
7252 if (findResult == dispatchMap->end()) {
7253 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Timeline."_s, protocol_method, "' was not found"_s));
7254 return;
7255 }
7256
7257 ((*this).*findResult->value)(protocol_requestId, WTFMove(protocol_parameters));
7258}
7259
7260void TimelineBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
7261{
7262#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7263 if (m_alternateDispatcher) {
7264 m_alternateDispatcher->enable(protocol_requestId);
7265 return;
7266 }
7267#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7268
7269 auto result = m_agent->enable();
7270 if (!result) {
7271 ASSERT(!result.error().isEmpty());
7272 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7273 return;
7274 }
7275
7276 auto protocol_jsonMessage = JSON::Object::create();
7277 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7278}
7279
7280void TimelineBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
7281{
7282#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7283 if (m_alternateDispatcher) {
7284 m_alternateDispatcher->disable(protocol_requestId);
7285 return;
7286 }
7287#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7288
7289 auto result = m_agent->disable();
7290 if (!result) {
7291 ASSERT(!result.error().isEmpty());
7292 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7293 return;
7294 }
7295
7296 auto protocol_jsonMessage = JSON::Object::create();
7297 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7298}
7299
7300void TimelineBackendDispatcher::start(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7301{
7302 auto in_opt_maxCallStackDepth = m_backendDispatcher->getInteger(protocol_parameters.get(), "maxCallStackDepth"_s, false);
7303 if (m_backendDispatcher->hasProtocolErrors()) {
7304 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Timeline.start' can't be processed"_s);
7305 return;
7306 }
7307
7308#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7309 if (m_alternateDispatcher) {
7310 m_alternateDispatcher->start(protocol_requestId, WTFMove(in_opt_maxCallStackDepth));
7311 return;
7312 }
7313#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7314
7315 auto result = m_agent->start(WTFMove(in_opt_maxCallStackDepth));
7316 if (!result) {
7317 ASSERT(!result.error().isEmpty());
7318 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7319 return;
7320 }
7321
7322 auto protocol_jsonMessage = JSON::Object::create();
7323 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7324}
7325
7326void TimelineBackendDispatcher::stop(long protocol_requestId, RefPtr<JSON::Object>&&)
7327{
7328#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7329 if (m_alternateDispatcher) {
7330 m_alternateDispatcher->stop(protocol_requestId);
7331 return;
7332 }
7333#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7334
7335 auto result = m_agent->stop();
7336 if (!result) {
7337 ASSERT(!result.error().isEmpty());
7338 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7339 return;
7340 }
7341
7342 auto protocol_jsonMessage = JSON::Object::create();
7343 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7344}
7345
7346void TimelineBackendDispatcher::setAutoCaptureEnabled(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7347{
7348 auto in_enabled = m_backendDispatcher->getBoolean(protocol_parameters.get(), "enabled"_s, true);
7349 if (m_backendDispatcher->hasProtocolErrors()) {
7350 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Timeline.setAutoCaptureEnabled' can't be processed"_s);
7351 return;
7352 }
7353
7354#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7355 if (m_alternateDispatcher) {
7356 m_alternateDispatcher->setAutoCaptureEnabled(protocol_requestId, *in_enabled);
7357 return;
7358 }
7359#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7360
7361 auto result = m_agent->setAutoCaptureEnabled(*in_enabled);
7362 if (!result) {
7363 ASSERT(!result.error().isEmpty());
7364 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7365 return;
7366 }
7367
7368 auto protocol_jsonMessage = JSON::Object::create();
7369 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7370}
7371
7372void TimelineBackendDispatcher::setInstruments(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7373{
7374 auto in_instruments = m_backendDispatcher->getArray(protocol_parameters.get(), "instruments"_s, true);
7375 if (m_backendDispatcher->hasProtocolErrors()) {
7376 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Timeline.setInstruments' can't be processed"_s);
7377 return;
7378 }
7379
7380#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7381 if (m_alternateDispatcher) {
7382 m_alternateDispatcher->setInstruments(protocol_requestId, in_instruments.releaseNonNull());
7383 return;
7384 }
7385#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7386
7387 auto result = m_agent->setInstruments(in_instruments.releaseNonNull());
7388 if (!result) {
7389 ASSERT(!result.error().isEmpty());
7390 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7391 return;
7392 }
7393
7394 auto protocol_jsonMessage = JSON::Object::create();
7395 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7396}
7397
7398Ref<WorkerBackendDispatcher> WorkerBackendDispatcher::create(BackendDispatcher& backendDispatcher, WorkerBackendDispatcherHandler* agent)
7399{
7400 return adoptRef(*new WorkerBackendDispatcher(backendDispatcher, agent));
7401}
7402
7403WorkerBackendDispatcher::WorkerBackendDispatcher(BackendDispatcher& backendDispatcher, WorkerBackendDispatcherHandler* agent)
7404 : SupplementalBackendDispatcher(backendDispatcher)
7405 , m_agent(agent)
7406{
7407 m_backendDispatcher->registerDispatcherForDomain("Worker"_s, this);
7408}
7409
7410void WorkerBackendDispatcher::dispatch(long protocol_requestId, const String& protocol_method, Ref<JSON::Object>&& protocol_message)
7411{
7412 Ref<WorkerBackendDispatcher> protect(*this);
7413
7414 auto protocol_parameters = protocol_message->getObject("params"_s);
7415
7416 if (protocol_method == "enable"_s) {
7417 enable(protocol_requestId, WTFMove(protocol_parameters));
7418 return;
7419 }
7420 if (protocol_method == "disable"_s) {
7421 disable(protocol_requestId, WTFMove(protocol_parameters));
7422 return;
7423 }
7424 if (protocol_method == "initialized"_s) {
7425 initialized(protocol_requestId, WTFMove(protocol_parameters));
7426 return;
7427 }
7428 if (protocol_method == "sendMessageToWorker"_s) {
7429 sendMessageToWorker(protocol_requestId, WTFMove(protocol_parameters));
7430 return;
7431 }
7432
7433 m_backendDispatcher->reportProtocolError(BackendDispatcher::MethodNotFound, makeString("'Worker."_s, protocol_method, "' was not found"_s));
7434}
7435
7436void WorkerBackendDispatcher::enable(long protocol_requestId, RefPtr<JSON::Object>&&)
7437{
7438#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7439 if (m_alternateDispatcher) {
7440 m_alternateDispatcher->enable(protocol_requestId);
7441 return;
7442 }
7443#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7444
7445 auto result = m_agent->enable();
7446 if (!result) {
7447 ASSERT(!result.error().isEmpty());
7448 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7449 return;
7450 }
7451
7452 auto protocol_jsonMessage = JSON::Object::create();
7453 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7454}
7455
7456void WorkerBackendDispatcher::disable(long protocol_requestId, RefPtr<JSON::Object>&&)
7457{
7458#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7459 if (m_alternateDispatcher) {
7460 m_alternateDispatcher->disable(protocol_requestId);
7461 return;
7462 }
7463#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7464
7465 auto result = m_agent->disable();
7466 if (!result) {
7467 ASSERT(!result.error().isEmpty());
7468 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7469 return;
7470 }
7471
7472 auto protocol_jsonMessage = JSON::Object::create();
7473 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7474}
7475
7476void WorkerBackendDispatcher::initialized(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7477{
7478 auto in_workerId = m_backendDispatcher->getString(protocol_parameters.get(), "workerId"_s, true);
7479 if (m_backendDispatcher->hasProtocolErrors()) {
7480 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Worker.initialized' can't be processed"_s);
7481 return;
7482 }
7483
7484#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7485 if (m_alternateDispatcher) {
7486 m_alternateDispatcher->initialized(protocol_requestId, in_workerId);
7487 return;
7488 }
7489#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7490
7491 auto result = m_agent->initialized(in_workerId);
7492 if (!result) {
7493 ASSERT(!result.error().isEmpty());
7494 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7495 return;
7496 }
7497
7498 auto protocol_jsonMessage = JSON::Object::create();
7499 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7500}
7501
7502void WorkerBackendDispatcher::sendMessageToWorker(long protocol_requestId, RefPtr<JSON::Object>&& protocol_parameters)
7503{
7504 auto in_workerId = m_backendDispatcher->getString(protocol_parameters.get(), "workerId"_s, true);
7505 auto in_message = m_backendDispatcher->getString(protocol_parameters.get(), "message"_s, true);
7506 if (m_backendDispatcher->hasProtocolErrors()) {
7507 m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidParams, "Some arguments of method 'Worker.sendMessageToWorker' can't be processed"_s);
7508 return;
7509 }
7510
7511#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7512 if (m_alternateDispatcher) {
7513 m_alternateDispatcher->sendMessageToWorker(protocol_requestId, in_workerId, in_message);
7514 return;
7515 }
7516#endif // ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
7517
7518 auto result = m_agent->sendMessageToWorker(in_workerId, in_message);
7519 if (!result) {
7520 ASSERT(!result.error().isEmpty());
7521 m_backendDispatcher->reportProtocolError(BackendDispatcher::ServerError, result.error());
7522 return;
7523 }
7524
7525 auto protocol_jsonMessage = JSON::Object::create();
7526 m_backendDispatcher->sendResponse(protocol_requestId, WTFMove(protocol_jsonMessage), false);
7527}
7528
7529} // namespace Inspector
7530